From: Rafael Espindola Date: Wed, 24 Jan 2018 18:58:32 +0000 (+0000) Subject: Don't create hidden dllimport global values. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28825cffe931202bdef523a652b652e1ffc26eaf;p=clang Don't create hidden dllimport global values. Hidden visibility is almost the opposite of dllimport. We were producing them before (dllimport wins in the existing llvm implementation), but now the llvm verifier produces an error. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323361 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 68c8287084..641c99119b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -694,6 +694,8 @@ llvm::ConstantInt *CodeGenModule::getSize(CharUnits size) { void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D, ForDefinition_t IsForDefinition) const { + if (GV->hasDLLImportStorageClass()) + return; // Internal definitions always have default visibility. if (GV->hasLocalLinkage()) { GV->setVisibility(llvm::GlobalValue::DefaultVisibility); diff --git a/test/CodeGenCXX/hidden-dllimport.cpp b/test/CodeGenCXX/hidden-dllimport.cpp new file mode 100644 index 0000000000..9de0d71084 --- /dev/null +++ b/test/CodeGenCXX/hidden-dllimport.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -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 @"\01?bar@foo@@QEAAXXZ"(%struct.foo*) + +struct __attribute__((dllimport)) foo { + void bar() {} +}; +void zed(foo *p) { p->bar(); }