[PATCH] [-cxx-abi microsoft] Emit linkonce_odr definitions for declarations of static data members with inline initializers (PR17689)

Hans Wennborg hans at chromium.org
Wed Nov 20 15:37:37 PST 2013


  Thanks for the comments! New patch coming up.


================
Comment at: lib/CodeGen/CodeGenModule.cpp:1613
@@ +1612,3 @@
+    // initializers as definitions.
+    if (getTarget().getCXXABI().isMicrosoft() && D->isStaticDataMember() &&
+        D->hasInit() && !D->isThisDeclarationADefinition())
----------------
Reid Kleckner wrote:
> The advice I've gotten from John is to add predicates to TargetCXXABI like isArgumentDestroyedByCallee() and use those instead of querying isMicrosoft() directly.  This would be something like isStaticDataMemberLinkOnce().
Sounds good to me.

================
Comment at: lib/CodeGen/CodeGenModule.cpp:1873
@@ +1872,3 @@
+  if (getTarget().getCXXABI().isMicrosoft() && D->isStaticDataMember() &&
+      InitExpr && !InitDecl->isThisDeclarationADefinition())
+    GV->setLinkage(llvm::GlobalVariable::LinkOnceODRLinkage);
----------------
Reid Kleckner wrote:
> Can you add some test cases for the other side of this?
> 
>   struct S { static const int x; }; const int S::x = 1;
> 
> Is S::x selectany or strong here?
It's strong. It's only when the var is initialized inline (in the class declaration) that things get special. I'll expand the test to cover this.


http://llvm-reviews.chandlerc.com/D2233



More information about the cfe-commits mailing list