summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-09-05 10:17:19 -0700
committerFangrui Song <i@maskray.me>2022-09-05 10:17:19 -0700
commit91d8324366f405e871aa8174ab61fc66912964dd (patch)
treec636e769a48115b80264c509475741d1b66848cc /clang/lib/CodeGen/CodeGenModule.cpp
parent05737fa209ba97b330739af3b00834c21b0547b7 (diff)
[MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration
dllimport/dllexport is incompatible with protected/hidden visibilities. (Arguably dllexport semantics is compatible with protected but let's reject the combo for simplicity.) When an explicit visibility attribute applies on a dllexport/dllimport declaration, report a Frontend error (Sema does not compute visibility). Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D133266
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f9087cdd5d4d..64a9e9d6f4c4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1099,8 +1099,6 @@ 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);
@@ -1111,6 +1109,14 @@ 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()));