[llvm-branch-commits] [cfe-branch] r195314 - Merging r195283:

Bill Wendling isanbard at gmail.com
Wed Nov 20 21:19:28 PST 2013


Author: void
Date: Wed Nov 20 23:19:27 2013
New Revision: 195314

URL: http://llvm.org/viewvc/llvm-project?rev=195314&view=rev
Log:
Merging r195283:
------------------------------------------------------------------------
r195283 | hans | 2013-11-20 16:15:56 -0800 (Wed, 20 Nov 2013) | 10 lines

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

This makes Clang emit a linkonce_odr definition for 'val' in the code below,
to be compatible with MSVC-compiled code:

  struct Foo {
    static const int val = 1;
  };

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

Added:
    cfe/branches/release_34/test/CodeGenCXX/ms-integer-static-data-members.cpp
      - copied unchanged from r195283, cfe/trunk/test/CodeGenCXX/ms-integer-static-data-members.cpp
Modified:
    cfe/branches/release_34/   (props changed)
    cfe/branches/release_34/lib/CodeGen/CGCXXABI.h
    cfe/branches/release_34/lib/CodeGen/CodeGenModule.cpp
    cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp

Propchange: cfe/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 20 23:19:27 2013
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174
+/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174,195283
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_34/lib/CodeGen/CGCXXABI.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGCXXABI.h?rev=195314&r1=195313&r2=195314&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/branches/release_34/lib/CodeGen/CGCXXABI.h Wed Nov 20 23:19:27 2013
@@ -373,6 +373,10 @@ public:
   /// Gets the deleted virtual member call name.
   virtual StringRef GetDeletedVirtualCallName() = 0;
 
+  /// \brief Returns true iff static data members that are initialized in the
+  /// class definition should have linkonce linkage.
+  virtual bool isInlineInitializedStaticDataMemberLinkOnce() { return false; }
+
   /**************************** Array cookies ******************************/
 
   /// Returns the extra size required in order to store the array

Modified: cfe/branches/release_34/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CodeGenModule.cpp?rev=195314&r1=195313&r2=195314&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CodeGenModule.cpp Wed Nov 20 23:19:27 2013
@@ -1607,6 +1607,13 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
         CXXThreadLocals.push_back(std::make_pair(D, GV));
       setTLSMode(GV, *D);
     }
+
+    // If required by the ABI, treat declarations of static data members with
+    // inline initializers as definitions.
+    if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() &&
+        D->isStaticDataMember() && D->hasInit() &&
+        !D->isThisDeclarationADefinition())
+      EmitGlobalVarDefinition(D);
   }
 
   if (AddrSpace != Ty->getAddressSpace())
@@ -1860,6 +1867,14 @@ void CodeGenModule::EmitGlobalVarDefinit
   llvm::GlobalValue::LinkageTypes Linkage = 
     GetLLVMLinkageVarDefinition(D, GV->isConstant());
   GV->setLinkage(Linkage);
+
+  // If required by the ABI, give definitions of static data members with inline
+  // initializers linkonce_odr linkage.
+  if (getCXXABI().isInlineInitializedStaticDataMemberLinkOnce() &&
+      D->isStaticDataMember() && InitExpr &&
+      !InitDecl->isThisDeclarationADefinition())
+    GV->setLinkage(llvm::GlobalVariable::LinkOnceODRLinkage);
+
   if (Linkage == llvm::GlobalVariable::CommonLinkage)
     // common vars aren't constant even if declared const.
     GV->setConstant(false);

Modified: cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp?rev=195314&r1=195313&r2=195314&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp Wed Nov 20 23:19:27 2013
@@ -50,6 +50,8 @@ public:
   // arbitrary.
   StringRef GetDeletedVirtualCallName() { return "_purecall"; }
 
+  bool isInlineInitializedStaticDataMemberLinkOnce() { return true; }
+
   llvm::Value *adjustToCompleteObject(CodeGenFunction &CGF,
                                       llvm::Value *ptr,
                                       QualType type);





More information about the llvm-branch-commits mailing list