]> granicus.if.org Git - llvm/commitdiff
Fix a reference-to-temporary introduced in r286607.
authorAdrian Prantl <aprantl@apple.com>
Fri, 11 Nov 2016 21:48:09 +0000 (21:48 +0000)
committerAdrian Prantl <aprantl@apple.com>
Fri, 11 Nov 2016 21:48:09 +0000 (21:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286640 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/GlobalMerge.cpp

index e0ffd475e64647d964466a23f03e4c81ff32add0..c3d49c035a4601f469db2ec0a6573c322bb02c66 100644 (file)
@@ -425,6 +425,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
   DEBUG(dbgs() << " Trying to merge set, starts with #"
                << GlobalSet.find_first() << "\n");
 
+  StringRef ExternalName;
   ssize_t i = GlobalSet.find_first();
   while (i != -1) {
     ssize_t j = 0;
@@ -433,7 +434,6 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
     std::vector<Constant*> Inits;
 
     bool HasExternal = false;
-    GlobalVariable *TheFirstExternal = nullptr;
     for (j = i; j != -1; j = GlobalSet.find_next(j)) {
       Type *Ty = Globals[j]->getValueType();
       MergedSize += DL.getTypeAllocSize(Ty);
@@ -445,7 +445,8 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
 
       if (Globals[j]->hasExternalLinkage() && !HasExternal) {
         HasExternal = true;
-        TheFirstExternal = Globals[j];
+        auto *TheFirstExternal = Globals[j];
+        ExternalName = TheFirstExternal->getName();
       }
     }
 
@@ -457,14 +458,15 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals,
     StructType *MergedTy = StructType::get(M.getContext(), Tys);
     Constant *MergedInit = ConstantStruct::get(MergedTy, Inits);
 
-    // On Darwin external linkage needs to be preserved, otherwise dsymutil
-    // cannot preserve the debug info for the merged variables.  If they have
-    // external linkage, use the symbol name of the first variable merged as the
-    // suffix of global symbol name.  This avoids a link-time naming conflict
-    // for the _MergedGlobals symbols.
+    // On Darwin external linkage needs to be preserved, otherwise
+    // dsymutil cannot preserve the debug info for the merged
+    // variables.  If they have external linkage, use the symbol name
+    // of the first variable merged as the suffix of global symbol
+    // name.  This avoids a link-time naming conflict for the
+    // _MergedGlobals symbols.
     Twine MergedName =
         (IsMachO && HasExternal)
-            ? "_MergedGlobals_" + TheFirstExternal->getName()
+            ? "_MergedGlobals_" + ExternalName
             : "_MergedGlobals";
     auto MergedLinkage = IsMachO ? Linkage : GlobalValue::PrivateLinkage;
     auto *MergedGV = new GlobalVariable(