summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-09 05:43:56 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-09 05:43:56 +0000
commite9efecaa5232becbb7e55484443b78637d58d54a (patch)
tree8d5d597cf64c6630c1f2016728712d2813caee6f /llvm/lib
parent0152e781468a2d5a2feb9630f717836ba7a7ba62 (diff)
downloadbcm5719-llvm-e9efecaa5232becbb7e55484443b78637d58d54a.tar.gz
bcm5719-llvm-e9efecaa5232becbb7e55484443b78637d58d54a.zip
AsmParser: Reject invalid mismatch between forward ref and def
Don't assume that the forward referenced entity was of the same global-kind as the new entity. This fixes PR21779. llvm-svn: 223754
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index e1c00cc4af0..df4a16abe1c 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -787,33 +787,36 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
if (Ty->isFunctionTy() || Ty->isLabelTy())
return Error(TyLoc, "invalid type for global variable");
- GlobalVariable *GV = nullptr;
+ GlobalValue *GVal = nullptr;
// See if the global was forward referenced, if so, use the global.
if (!Name.empty()) {
- if (GlobalValue *GVal = M->getNamedValue(Name)) {
+ GVal = M->getNamedValue(Name);
+ if (GVal) {
if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
return Error(NameLoc, "redefinition of global '@" + Name + "'");
- GV = cast<GlobalVariable>(GVal);
}
} else {
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
I = ForwardRefValIDs.find(NumberedVals.size());
if (I != ForwardRefValIDs.end()) {
- GV = cast<GlobalVariable>(I->second.first);
+ GVal = I->second.first;
ForwardRefValIDs.erase(I);
}
}
+ GlobalVariable *GV;
if (!GV) {
GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, nullptr,
Name, nullptr, GlobalVariable::NotThreadLocal,
AddrSpace);
} else {
- if (GV->getType()->getElementType() != Ty)
+ if (GVal->getType()->getElementType() != Ty)
return Error(TyLoc,
"forward reference and definition of global have different types");
+ GV = cast<GlobalVariable>(GVal);
+
// Move the forward-reference to the correct spot in the module.
M->getGlobalList().splice(M->global_end(), M->getGlobalList(), GV);
}
OpenPOWER on IntegriCloud