r199220 - Update CodeGen to use DLL storage class for dllimport/dllexport
Nico Rieck
nico.rieck at gmail.com
Tue Jan 14 07:23:53 PST 2014
Author: nrieck
Date: Tue Jan 14 09:23:53 2014
New Revision: 199220
URL: http://llvm.org/viewvc/llvm-project?rev=199220&view=rev
Log:
Update CodeGen to use DLL storage class for dllimport/dllexport
With the old linkage types removed, set the linkage to external for both
dllimport and dllexport to reflect what's currently supported.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/dllimport-dllexport.c
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=199220&r1=199219&r2=199220&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jan 14 09:23:53 2014
@@ -593,7 +593,7 @@ CodeGenModule::getFunctionLinkage(Global
return llvm::Function::InternalLinkage;
if (D->hasAttr<DLLExportAttr>())
- return llvm::Function::DLLExportLinkage;
+ return llvm::Function::ExternalLinkage;
if (D->hasAttr<WeakAttr>())
return llvm::Function::WeakAnyLinkage;
@@ -808,7 +808,8 @@ void CodeGenModule::SetFunctionAttribute
// overridden by a definition.
if (FD->hasAttr<DLLImportAttr>()) {
- F->setLinkage(llvm::Function::DLLImportLinkage);
+ F->setLinkage(llvm::Function::ExternalLinkage);
+ F->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
} else if (FD->hasAttr<WeakAttr>() ||
FD->isWeakImported()) {
// "extern_weak" is overloaded in LLVM; we probably should have
@@ -816,6 +817,8 @@ void CodeGenModule::SetFunctionAttribute
F->setLinkage(llvm::Function::ExternalWeakLinkage);
} else {
F->setLinkage(llvm::Function::ExternalLinkage);
+ if (FD->hasAttr<DLLExportAttr>())
+ F->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
LinkageInfo LV = FD->getLinkageAndVisibility();
if (LV.getLinkage() == ExternalLinkage && LV.isVisibilityExplicit()) {
@@ -1608,9 +1611,10 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
if (LV.getLinkage() != ExternalLinkage) {
// Don't set internal linkage on declarations.
} else {
- if (D->hasAttr<DLLImportAttr>())
- GV->setLinkage(llvm::GlobalValue::DLLImportLinkage);
- else if (D->hasAttr<WeakAttr>() || D->isWeakImported())
+ if (D->hasAttr<DLLImportAttr>()) {
+ GV->setLinkage(llvm::GlobalValue::ExternalLinkage);
+ GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+ } else if (D->hasAttr<WeakAttr>() || D->isWeakImported())
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
// Set visibility on a declaration only if it's explicit.
@@ -1883,6 +1887,10 @@ void CodeGenModule::EmitGlobalVarDefinit
llvm::GlobalValue::LinkageTypes Linkage =
GetLLVMLinkageVarDefinition(D, GV->isConstant());
GV->setLinkage(Linkage);
+ if (D->hasAttr<DLLImportAttr>())
+ GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
+ else if (D->hasAttr<DLLExportAttr>())
+ GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
// If required by the ABI, give definitions of static data members with inline
// initializers linkonce_odr linkage.
@@ -1925,9 +1933,9 @@ CodeGenModule::GetLLVMLinkageVarDefiniti
if (Linkage == GVA_Internal)
return llvm::Function::InternalLinkage;
else if (D->hasAttr<DLLImportAttr>())
- return llvm::Function::DLLImportLinkage;
+ return llvm::Function::ExternalLinkage;
else if (D->hasAttr<DLLExportAttr>())
- return llvm::Function::DLLExportLinkage;
+ return llvm::Function::ExternalLinkage;
else if (D->hasAttr<SelectAnyAttr>()) {
// selectany symbols are externally visible, so use weak instead of
// linkonce. MSVC optimizes away references to const selectany globals, so
@@ -2250,9 +2258,9 @@ void CodeGenModule::EmitAliasDefinition(
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// The dllexport attribute is ignored for undefined symbols.
if (FD->hasBody())
- GA->setLinkage(llvm::Function::DLLExportLinkage);
+ GA->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
} else {
- GA->setLinkage(llvm::Function::DLLExportLinkage);
+ GA->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
}
} else if (D->hasAttr<WeakAttr>() ||
D->hasAttr<WeakRefAttr>() ||
Modified: cfe/trunk/test/CodeGen/dllimport-dllexport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/dllimport-dllexport.c?rev=199220&r1=199219&r2=199220&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/dllimport-dllexport.c (original)
+++ cfe/trunk/test/CodeGen/dllimport-dllexport.c Tue Jan 14 09:23:53 2014
@@ -1,5 +1,10 @@
// RUN: %clang_cc1 -triple i386-mingw32 -emit-llvm < %s | FileCheck %s
+__attribute__((dllexport)) int bar1 = 2;
+// CHECK-LABEL: @bar1 = dllexport global i32 2
+__attribute__((dllimport)) extern int bar2;
+// CHECK-LABEL: @bar2 = external dllimport global i32
+
void __attribute__((dllimport)) foo1();
void __attribute__((dllexport)) foo1(){}
// CHECK-LABEL: define dllexport void @foo1
@@ -10,3 +15,8 @@ __declspec(dllimport) void foo3();
__declspec(dllexport) void foo3(){}
// CHECK-LABEL: define dllexport void @foo3
__declspec(dllexport) void foo4();
+
+__declspec(dllimport) void foo5();
+// CHECK-LABEL: declare dllimport void @foo5
+
+int use() { foo5(); return bar2; }
More information about the cfe-commits
mailing list