From: Adrian Prantl Date: Fri, 11 Nov 2016 21:48:09 +0000 (+0000) Subject: Fix a reference-to-temporary introduced in r286607. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd5b334349a8770045ed3e89b4489adbc8e5f099;p=llvm Fix a reference-to-temporary introduced in r286607. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286640 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/GlobalMerge.cpp b/lib/CodeGen/GlobalMerge.cpp index e0ffd475e64..c3d49c035a4 100644 --- a/lib/CodeGen/GlobalMerge.cpp +++ b/lib/CodeGen/GlobalMerge.cpp @@ -425,6 +425,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl &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 &Globals, std::vector 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 &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 &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(