r250757 - [MS ABI] Give linkonce_odr, instead of external_linkage, to certain kinds of static data members

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 16:22:50 PDT 2015


Author: majnemer
Date: Mon Oct 19 18:22:49 2015
New Revision: 250757

URL: http://llvm.org/viewvc/llvm-project?rev=250757&view=rev
Log:
[MS ABI] Give linkonce_odr, instead of external_linkage, to certain kinds of static data members

Out-of-line definitions of static data members which have an inline
initializer must get GVA_DiscardableODR linkage instead of
GVA_StrongExternal linkage.

MSVC 2013's behavior is different with respect to this and would cause
link errors if one TU provided a definition while another did not.
MSVC 2015 fixed this bug, making this OK.  Note that the 2015 behavior
is always compatible with 2013: it never produces a strong definition.

This essentially reverts r237787.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
    cfe/trunk/test/CodeGenCXX/ms-integer-static-data-members.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=250757&r1=250756&r2=250757&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Oct 19 18:22:49 2015
@@ -5035,8 +5035,8 @@ CharUnits ASTContext::getObjCEncodingTyp
 bool ASTContext::isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const {
   return getTargetInfo().getCXXABI().isMicrosoft() &&
          VD->isStaticDataMember() &&
-         VD->getType()->isIntegralOrEnumerationType() && VD->isFirstDecl() &&
-         !VD->isOutOfLine() && VD->hasInit();
+         VD->getType()->isIntegralOrEnumerationType() &&
+         !VD->getFirstDecl()->isOutOfLine() && VD->getFirstDecl()->hasInit();
 }
 
 static inline 

Modified: cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport-members.cpp?rev=250757&r1=250756&r2=250757&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllexport-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport-members.cpp Mon Oct 19 18:22:49 2015
@@ -110,10 +110,10 @@ 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
-  // MSC-DAG: @"\01?StaticConstFieldEqualInit at ExportMembers@@2HB" = dllexport constant i32 1, comdat, align 4
-  // MSC-DAG: @"\01?StaticConstFieldBraceInit at ExportMembers@@2HB" = dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
   // MSC-DAG: @"\01?StaticConstFieldRefNotDef at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
-  // MSC-DAG: @"\01?ConstexprField at ExportMembers@@2HB"            = dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?ConstexprField at ExportMembers@@2HB"            = weak_odr dllexport constant i32 1, comdat, 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
@@ -236,10 +236,10 @@ 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" = dllexport constant i32 1, comdat, align 4
-  // MSC-DAG: @"\01?StaticConstFieldBraceInit at Nested@ExportMembers@@2HB" = dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?StaticConstFieldEqualInit at Nested@ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?StaticConstFieldBraceInit at Nested@ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
   // MSC-DAG: @"\01?StaticConstFieldRefNotDef at Nested@ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
-  // MSC-DAG: @"\01?ConstexprField at Nested@ExportMembers@@2HB"            = dllexport constant i32 1, comdat, align 4
+  // MSC-DAG: @"\01?ConstexprField at Nested@ExportMembers@@2HB"            = weak_odr dllexport constant i32 1, comdat, 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/ms-integer-static-data-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms-integer-static-data-members.cpp?rev=250757&r1=250756&r2=250757&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ms-integer-static-data-members.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ms-integer-static-data-members.cpp Mon Oct 19 18:22:49 2015
@@ -42,10 +42,10 @@ const int S::OutOfLine_Def_Ref = 5;
 // CHECK-DAG: @"\01?Inline_NotDef_Ref at S@@2HB" = linkonce_odr constant i32 5, comdat, align 4
 
 // Inline initialization, real definiton, not referenced.
-// CHECK-DAG: @"\01?Inline_Def_NotRef at S@@2HB" = constant i32 5, align 4
+// CHECK-NOT: @"\01?Inline_Def_NotRef at S@@2HB" = constant i32 5, align 4
 
 // Inline initialization, real definiton, referenced.
-// CHECK-DAG: @"\01?Inline_Def_Ref at S@@2HB" = constant i32 5, comdat, align 4
+// CHECK-DAG: @"\01?Inline_Def_Ref at S@@2HB" = linkonce_odr constant i32 5, comdat, align 4
 
 // Out-of-line initialization.
 // CHECK-DAG: @"\01?OutOfLine_Def_NotRef at S@@2HB" = constant i32 5, align 4




More information about the cfe-commits mailing list