[clang] 1a4d851 - [MinGW] Ignore -fvisibility/-fvisibility-inlines-hidden for dllexport

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 09:59:25 PDT 2022


Author: Fangrui Song
Date: 2022-09-02T09:59:16-07:00
New Revision: 1a4d851d272d141fb39ff9a0b2572dfa4411c5c5

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

LOG: [MinGW] Ignore -fvisibility/-fvisibility-inlines-hidden for dllexport

Similar to 123ce97fac78bc4519afd5d2aba17c59c5717aad for dllimport: dllexport
expresses a non-hidden visibility intention. We can consider it explicit and
therefore it should override the global visibility setting (see AST/Decl.cpp
"NamedDecl Implementation").

Adding the special case to CodeGenModule::setGlobalVisibility is somewhat weird,
but allows we to add the code in one place instead of many in AST/Decl.cpp.

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

Added: 
    clang/test/CodeGenCXX/dllstorage-visibility.cpp

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    clang/test/CodeGenCXX/hidden-dllimport.cpp


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index bb0970e3e36fa..f9087cdd5d4dc 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1099,7 +1099,7 @@ llvm::ConstantInt *CodeGenModule::getSize(CharUnits size) {
 
 void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
                                         const NamedDecl *D) const {
-  if (GV->hasDLLImportStorageClass())
+  if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass())
     return;
   // Internal definitions always have default visibility.
   if (GV->hasLocalLinkage()) {

diff  --git a/clang/test/CodeGenCXX/dllstorage-visibility.cpp b/clang/test/CodeGenCXX/dllstorage-visibility.cpp
new file mode 100644
index 0000000000000..af164edc24820
--- /dev/null
+++ b/clang/test/CodeGenCXX/dllstorage-visibility.cpp
@@ -0,0 +1,26 @@
+/// dllimport and dllexport express non-hidden intention. Don't apply hidden visibility.
+
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-msvc -fdeclspec -fvisibility-inlines-hidden -o - %s | FileCheck %s --check-prefix=MSVC
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-gnu -fdeclspec -fvisibility-inlines-hidden -o - %s | FileCheck %s --check-prefix=GNU
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-gnu -fdeclspec -fvisibility hidden -o - %s | FileCheck %s --check-prefix=GNU
+
+#define CONCAT2(x, y) x##y
+#define CONCAT(x, y) CONCAT2(x, y)
+#define USE(func) void CONCAT(use, __LINE__)() { func(); }
+
+// MSVC-DAG: declare dllimport void @"?bar at foo@@QEAAXXZ"(
+// GNU-DAG: define linkonce_odr hidden void @_ZN3foo3barEv(
+
+struct __attribute__((dllimport)) foo {
+  void bar() {}
+};
+void zed(foo *p) { p->bar(); }
+
+// MSVC-DAG: define dso_local dllexport void @"?exported@@YAXXZ"(
+// GNU-DAG: define dso_local dllexport void @_Z8exportedv(
+__attribute__((dllexport)) void exported() {}
+
+// MSVC-DAG: define weak_odr dso_local dllexport void @"?exported_inline@@YAXXZ"(
+// GNU-DAG: define weak_odr dso_local dllexport void @_Z15exported_inlinev(
+__declspec(dllexport) inline void exported_inline() {}
+USE(exported_inline)

diff  --git a/clang/test/CodeGenCXX/hidden-dllimport.cpp b/clang/test/CodeGenCXX/hidden-dllimport.cpp
deleted file mode 100644
index c9e0304b6ff4d..0000000000000
--- a/clang/test/CodeGenCXX/hidden-dllimport.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-pc-windows-msvc -emit-llvm -fvisibility-inlines-hidden -o - %s | FileCheck %s
-
-// We used to declare this hidden dllimport, which is contradictory.
-
-// CHECK: declare dllimport void @"?bar at foo@@QEAAXXZ"(%struct.foo* {{[^,]*}})
-
-struct __attribute__((dllimport)) foo {
-  void bar() {}
-};
-void zed(foo *p) { p->bar(); }


        


More information about the cfe-commits mailing list