]> granicus.if.org Git - clang/commitdiff
Update CodeGen to use DLL storage class for dllimport/dllexport
authorNico Rieck <nico.rieck@gmail.com>
Tue, 14 Jan 2014 15:23:53 +0000 (15:23 +0000)
committerNico Rieck <nico.rieck@gmail.com>
Tue, 14 Jan 2014 15:23:53 +0000 (15:23 +0000)
With the old linkage types removed, set the linkage to external for both
dllimport and dllexport to reflect what's currently supported.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199220 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/dllimport-dllexport.c

index c9f3ea38f2499bdeb5886ed98624c2b65c7c49b2..a3f3af38d968ccde2797a904cd5b5dabc556c304 100644 (file)
@@ -593,7 +593,7 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
     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::SetFunctionAttributes(GlobalDecl GD,
   // 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::SetFunctionAttributes(GlobalDecl GD,
     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(StringRef MangledName,
     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::EmitGlobalVarDefinition(const VarDecl *D) {
   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::GetLLVMLinkageVarDefinition(const VarDecl *D, bool isConstant) {
   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(GlobalDecl GD) {
     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>() ||
index e70ac03f04c75f15ca071acca40d45e5a9f80be3..b005e34b788da8790ea577579bb02572229083e1 100644 (file)
@@ -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; }