[clang] f34ecb5 - [clang] Don't emit type tests for dllexport/import classes

Arthur Eubanks via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 25 14:06:02 PDT 2023


Author: Arthur Eubanks
Date: 2023-04-25T14:00:57-07:00
New Revision: f34ecb50e2c03e27b5785576545aab07b3b19a94

URL: https://github.com/llvm/llvm-project/commit/f34ecb50e2c03e27b5785576545aab07b3b19a94
DIFF: https://github.com/llvm/llvm-project/commit/f34ecb50e2c03e27b5785576545aab07b3b19a94.diff

LOG: [clang] Don't emit type tests for dllexport/import classes

According to https://clang.llvm.org/docs/LTOVisibility.html, classes on
Windows with dllimport/export receive public LTO visibility and
therefore should not participate in WPD.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D129700

Added: 
    

Modified: 
    clang/lib/CodeGen/CGVTables.cpp
    clang/test/CodeGenCXX/lto-visibility-inference.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index a257de859d4e8..32259d1e4cbff 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1212,7 +1212,8 @@ void CodeGenModule::EmitDeferredVTables() {
 }
 
 bool CodeGenModule::AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD) {
-  if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>())
+  if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>() ||
+      RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
     return true;
 
   if (!getCodeGenOpts().LTOVisibilityPublicStd)
@@ -1239,13 +1240,9 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
   if (!isExternallyVisible(LV.getLinkage()))
     return true;
 
-  if (getTriple().isOSBinFormatCOFF()) {
-    if (RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
-      return false;
-  } else {
-    if (LV.getVisibility() != HiddenVisibility)
-      return false;
-  }
+  if (!getTriple().isOSBinFormatCOFF() &&
+      LV.getVisibility() != HiddenVisibility)
+    return false;
 
   return !AlwaysHasLTOVisibilityPublic(RD);
 }

diff  --git a/clang/test/CodeGenCXX/lto-visibility-inference.cpp b/clang/test/CodeGenCXX/lto-visibility-inference.cpp
index 1246743115604..e7ce3436a88b1 100644
--- a/clang/test/CodeGenCXX/lto-visibility-inference.cpp
+++ b/clang/test/CodeGenCXX/lto-visibility-inference.cpp
@@ -74,10 +74,10 @@ void f(C1 *c1, C2 *c2, C3 *c3, C4 *c4, C5 *c5, C6 *c6, std::C7 *c7,
   // MS: type.test{{.*}}!"?AUC2@@"
   c2->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C3"
-  // MS: type.test{{.*}}!"?AUC3@@"
+  // MS-NOT: type.test{{.*}}!"?AUC3@@"
   c3->f();
   // ITANIUM: type.test{{.*}}!"_ZTS2C4"
-  // MS: type.test{{.*}}!"?AUC4@@"
+  // MS-NOT: type.test{{.*}}!"?AUC4@@"
   c4->f();
   // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C5"
   // MS-NOT: type.test{{.*}}!"?AUC5@@"


        


More information about the cfe-commits mailing list