r209826 - MS ABI: Emit static data members with proper linkage

Nico Rieck nico.rieck at gmail.com
Thu May 29 09:50:46 PDT 2014


Author: nrieck
Date: Thu May 29 11:50:46 2014
New Revision: 209826

URL: http://llvm.org/viewvc/llvm-project?rev=209826&view=rev
Log:
MS ABI: Emit static data members with proper linkage

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
    cfe/trunk/test/CodeGenCXX/dllimport-members.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=209826&r1=209825&r2=209826&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May 29 11:50:46 2014
@@ -1964,10 +1964,15 @@ llvm::GlobalValue::LinkageTypes CodeGenM
 
   // If required by the ABI, give definitions of static data members with inline
   // initializers at least linkonce_odr linkage.
+  auto const VD = dyn_cast<VarDecl>(D);
   if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() &&
-      isa<VarDecl>(D) &&
-      isVarDeclInlineInitializedStaticDataMember(cast<VarDecl>(D)))
+      VD && isVarDeclInlineInitializedStaticDataMember(VD)) {
+    if (VD->hasAttr<DLLImportAttr>())
+      return llvm::GlobalValue::AvailableExternallyLinkage;
+    if (VD->hasAttr<DLLExportAttr>())
+      return llvm::GlobalValue::WeakODRLinkage;
     return llvm::GlobalValue::LinkOnceODRLinkage;
+  }
 
   // C++ doesn't have tentative definitions and thus cannot have common
   // linkage.

Modified: cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport-members.cpp?rev=209826&r1=209825&r2=209826&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllexport-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport-members.cpp Thu May 29 11:50:46 2014
@@ -119,10 +119,9 @@ public:
 
   // MSC-DAG: @"\01?StaticField at ExportMembers@@2HA"               = dllexport global i32 1, align 4
   // MSC-DAG: @"\01?StaticConstField at ExportMembers@@2HB"          = dllexport constant i32 1, align 4
-  // FIXME: These three should be weak_odr.
-  // MSC-DAG: @"\01?StaticConstFieldEqualInit at ExportMembers@@2HB" = linkonce_odr dllexport constant i32 1, align 4
-  // MSC-DAG: @"\01?StaticConstFieldBraceInit at ExportMembers@@2HB" = linkonce_odr dllexport constant i32 1, align 4
-  // MSC-DAG: @"\01?ConstexprField at ExportMembers@@2HB"            = linkonce_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?ConstexprField at ExportMembers@@2HB"            = weak_odr dllexport constant i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers11StaticFieldE                   = dllexport global i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers16StaticConstFieldE              = dllexport constant i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers25StaticConstFieldEqualInitE     = dllexport constant i32 1, align 4
@@ -243,9 +242,9 @@ public:
 
   // MSC-DAG: @"\01?StaticField at Nested@ExportMembers@@2HA"               = dllexport global i32 1, align 4
   // MSC-DAG: @"\01?StaticConstField at Nested@ExportMembers@@2HB"          = dllexport constant i32 1, align 4
-  // MSC-DAG: @"\01?StaticConstFieldEqualInit at Nested@ExportMembers@@2HB" = linkonce_odr dllexport constant i32 1, align 4
-  // MSC-DAG: @"\01?StaticConstFieldBraceInit at Nested@ExportMembers@@2HB" = linkonce_odr dllexport constant i32 1, align 4
-  // MSC-DAG: @"\01?ConstexprField at Nested@ExportMembers@@2HB"            = linkonce_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at Nested@ExportMembers@@2HB" = weak_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at Nested@ExportMembers@@2HB" = weak_odr dllexport constant i32 1, align 4
+  // MSC-DAG: @"\01?ConstexprField at Nested@ExportMembers@@2HB"            = weak_odr dllexport constant i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers6Nested11StaticFieldE                   = dllexport global i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers6Nested16StaticConstFieldE              = dllexport constant i32 1, align 4
   // GNU-DAG: @_ZN13ExportMembers6Nested25StaticConstFieldEqualInitE     = dllexport constant i32 1, align 4

Modified: cfe/trunk/test/CodeGenCXX/dllimport-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-members.cpp?rev=209826&r1=209825&r2=209826&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport-members.cpp Thu May 29 11:50:46 2014
@@ -178,9 +178,9 @@ public:
 
   // MSC-DAG: @"\01?StaticField at ImportMembers@@2HA"               = external dllimport global i32
   // MSC-DAG: @"\01?StaticConstField at ImportMembers@@2HB"          = external dllimport constant i32
-  // MSC-DAG-FIXME: @"\01?StaticConstFieldEqualInit at ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
-  // MSC-DAG-FIXME: @"\01?StaticConstFieldBraceInit at ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
-  // MSC-DAG-FIXME: @"\01?ConstexprField at ImportMembers@@2HB"            = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?ConstexprField at ImportMembers@@2HB"            = available_externally dllimport constant i32 1, align 4
   // GNU-DAG: @_ZN13ImportMembers11StaticFieldE                   = external dllimport global i32
   // GNU-DAG: @_ZN13ImportMembers16StaticConstFieldE              = external dllimport constant i32
   // GNU-DAG: @_ZN13ImportMembers25StaticConstFieldEqualInitE     = external dllimport constant i32
@@ -188,11 +188,9 @@ public:
   // GNU-DAG: @_ZN13ImportMembers14ConstexprFieldE                = external dllimport constant i32
   __declspec(dllimport) static         int  StaticField;
   __declspec(dllimport) static  const  int  StaticConstField;
-  #ifndef MSABI // FIXME
   __declspec(dllimport) static  const  int  StaticConstFieldEqualInit = 1;
   __declspec(dllimport) static  const  int  StaticConstFieldBraceInit{1};
   __declspec(dllimport) constexpr static int ConstexprField = 1;
-  #endif
 
   template<int Line, typename T> friend void useMemFun();
 };
@@ -230,11 +228,9 @@ USEMF(ImportMembers, ignored)
 
 USEMV(ImportMembers, StaticField)
 USEMV(ImportMembers, StaticConstField)
-#ifndef MSABI // FIXME
 USEMV(ImportMembers, StaticConstFieldEqualInit)
 USEMV(ImportMembers, StaticConstFieldBraceInit)
 USEMV(ImportMembers, ConstexprField)
-#endif
 
 
 // Import individual members of a nested class.
@@ -355,9 +351,9 @@ public:
 
   // MSC-DAG: @"\01?StaticField at Nested@ImportMembers@@2HA"               = external dllimport global i32
   // MSC-DAG: @"\01?StaticConstField at Nested@ImportMembers@@2HB"          = external dllimport constant i32
-  // MSC-DAG-FIXME: @"\01?StaticConstFieldEqualInit at Nested@ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
-  // MSC-DAG-FIXME: @"\01?StaticConstFieldBraceInit at Nested@ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
-  // MSC-DAG-FIXME: @"\01?ConstexprField at Nested@ImportMembers@@2HB"            = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at Nested@ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at Nested@ImportMembers@@2HB" = available_externally dllimport constant i32 1, align 4
+  // MSC-DAG: @"\01?ConstexprField at Nested@ImportMembers@@2HB"            = available_externally dllimport constant i32 1, align 4
   // GNU-DAG: @_ZN13ImportMembers6Nested11StaticFieldE                   = external dllimport global i32
   // GNU-DAG: @_ZN13ImportMembers6Nested16StaticConstFieldE              = external dllimport constant i32
   // GNU-DAG: @_ZN13ImportMembers6Nested25StaticConstFieldEqualInitE     = external dllimport constant i32
@@ -365,11 +361,9 @@ public:
   // GNU-DAG: @_ZN13ImportMembers6Nested14ConstexprFieldE                = external dllimport constant i32
   __declspec(dllimport) static         int  StaticField;
   __declspec(dllimport) static  const  int  StaticConstField;
-  #ifndef MSABI // FIXME
   __declspec(dllimport) static  const  int  StaticConstFieldEqualInit = 1;
   __declspec(dllimport) static  const  int  StaticConstFieldBraceInit{1};
   __declspec(dllimport) constexpr static int ConstexprField = 1;
-  #endif
 
   template<int Line, typename T> friend void useMemFun();
 };
@@ -407,11 +401,9 @@ USEMF(ImportMembers::Nested, ignored)
 
 USEMV(ImportMembers::Nested, StaticField)
 USEMV(ImportMembers::Nested, StaticConstField)
-#ifndef MSABI // FIXME
 USEMV(ImportMembers::Nested, StaticConstFieldEqualInit)
 USEMV(ImportMembers::Nested, StaticConstFieldBraceInit)
 USEMV(ImportMembers::Nested, ConstexprField)
-#endif
 
 
 // Import special member functions.





More information about the cfe-commits mailing list