aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2016-11-11 21:48:09 +0000
committerAdrian Prantl <aprantl@apple.com>2016-11-11 21:48:09 +0000
commitcd5b334349a8770045ed3e89b4489adbc8e5f099 (patch)
treee4a16d345f7d42d4aae11cad57ee0a8e2c6d81b4
parent085827f84324b95e41ede1a9507e7d2fb8d505a9 (diff)
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
-rw-r--r--lib/CodeGen/GlobalMerge.cpp18
1 files changed, 10 insertions, 8 deletions
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<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(