[clang] bc502d9 - Revert D133266 "[MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration"
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 7 16:06:28 PDT 2022
Author: Fangrui Song
Date: 2022-09-07T16:06:19-07:00
New Revision: bc502d9c24f8fce3b90e3fe8a8a9ca18894e68cb
URL: https://github.com/llvm/llvm-project/commit/bc502d9c24f8fce3b90e3fe8a8a9ca18894e68cb
DIFF: https://github.com/llvm/llvm-project/commit/bc502d9c24f8fce3b90e3fe8a8a9ca18894e68cb.diff
LOG: Revert D133266 "[MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration"
This reverts commit 91d8324366f405e871aa8174ab61fc66912964dd.
The combo dllexport protected makes sense and is used by PlayStation.
Will change the patch to allow dllexport protected.
Added:
Modified:
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/dllstorage-visibility.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 224c290219ef6..50f7e2b9221d0 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -282,8 +282,6 @@ def err_duplicate_mangled_name : Error<
"definition with same mangled name '%0' as another definition">;
def err_cyclic_alias : Error<
"%select{alias|ifunc}0 definition is part of a cycle">;
-def err_non_default_visibility_dllstorage : Error<
- "non-default visibility cannot be applied to '%0' declaration">;
def err_ifunc_resolver_return : Error<
"ifunc resolver function must return a pointer">;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 64a9e9d6f4c42..f9087cdd5d4dc 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1099,6 +1099,8 @@ llvm::ConstantInt *CodeGenModule::getSize(CharUnits size) {
void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
const NamedDecl *D) const {
+ if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass())
+ return;
// Internal definitions always have default visibility.
if (GV->hasLocalLinkage()) {
GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
@@ -1109,14 +1111,6 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
// Set visibility for definitions, and for declarations if requested globally
// or set explicitly.
LinkageInfo LV = D->getLinkageAndVisibility();
- if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) {
- // Reject explicit non-default visibility on dllexport/dllimport.
- if (LV.isVisibilityExplicit() && LV.getVisibility() != DefaultVisibility)
- getDiags().Report(D->getLocation(),
- diag::err_non_default_visibility_dllstorage)
- << (GV->hasDLLExportStorageClass() ? "dllexport" : "dllimport");
- return;
- }
if (LV.isVisibilityExplicit() || getLangOpts().SetVisibilityForExternDecls ||
!GV->isDeclarationForLinker())
GV->setVisibility(GetLLVMVisibility(LV.getVisibility()));
diff --git a/clang/test/CodeGenCXX/dllstorage-visibility.cpp b/clang/test/CodeGenCXX/dllstorage-visibility.cpp
index 0e3c32ec9aecd..8f34afbb801ff 100644
--- a/clang/test/CodeGenCXX/dllstorage-visibility.cpp
+++ b/clang/test/CodeGenCXX/dllstorage-visibility.cpp
@@ -4,18 +4,10 @@
// 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
-// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -DERR1 -o - %s
-// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -fvisibility=hidden -DERR1 -o - %s
-// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -DERR2 -o - %s
-
#define CONCAT2(x, y) x##y
#define CONCAT(x, y) CONCAT2(x, y)
#define USE(func) void CONCAT(use, __LINE__)() { func(); }
-#define HIDDEN __attribute__((visibility("hidden")))
-#define PROTECTED __attribute__((visibility("protected")))
-#define DEFAULT __attribute__((visibility("default")))
-
// MSVC-DAG: declare dllimport void @"?bar at foo@@QEAAXXZ"(
// GNU-DAG: define linkonce_odr hidden void @_ZN3foo3barEv(
@@ -32,17 +24,3 @@ __attribute__((dllexport)) void exported() {}
// GNU-DAG: define weak_odr dso_local dllexport void @_Z15exported_inlinev(
__declspec(dllexport) inline void exported_inline() {}
USE(exported_inline)
-
-#if defined(ERR1)
-// expected-error at +1 {{non-default visibility cannot be applied to 'dllimport' declaration}}
-__attribute__((dllimport)) HIDDEN void imported_hidden();
-
-__attribute__((dllexport)) DEFAULT void exported_default() {}
-// expected-error at +1 {{non-default visibility cannot be applied to 'dllexport' declaration}}
-__attribute__((dllexport)) HIDDEN void exported_hidden() { imported_hidden(); }
-#elif defined(ERR2)
-struct PROTECTED C {
- // expected-error at +1 {{non-default visibility cannot be applied to 'dllexport' declaration}}
- __attribute__((dllexport)) void exported_protected() {}
-};
-#endif
More information about the cfe-commits
mailing list