Revert "AsmParser: Reject invalid mismatch between forward ref and def"

This reverts commit r223754.  I've upset the buildbots.

llvm-svn: 223755
This commit is contained in:
David Majnemer 2014-12-09 05:50:11 +00:00
parent e9efecaa52
commit 8d3e580cc7
2 changed files with 5 additions and 12 deletions

View File

@ -787,36 +787,33 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
if (Ty->isFunctionTy() || Ty->isLabelTy()) if (Ty->isFunctionTy() || Ty->isLabelTy())
return Error(TyLoc, "invalid type for global variable"); return Error(TyLoc, "invalid type for global variable");
GlobalValue *GVal = nullptr; GlobalVariable *GV = nullptr;
// See if the global was forward referenced, if so, use the global. // See if the global was forward referenced, if so, use the global.
if (!Name.empty()) { if (!Name.empty()) {
GVal = M->getNamedValue(Name); if (GlobalValue *GVal = M->getNamedValue(Name)) {
if (GVal) {
if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal)) if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
return Error(NameLoc, "redefinition of global '@" + Name + "'"); return Error(NameLoc, "redefinition of global '@" + Name + "'");
GV = cast<GlobalVariable>(GVal);
} }
} else { } else {
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
I = ForwardRefValIDs.find(NumberedVals.size()); I = ForwardRefValIDs.find(NumberedVals.size());
if (I != ForwardRefValIDs.end()) { if (I != ForwardRefValIDs.end()) {
GVal = I->second.first; GV = cast<GlobalVariable>(I->second.first);
ForwardRefValIDs.erase(I); ForwardRefValIDs.erase(I);
} }
} }
GlobalVariable *GV;
if (!GV) { if (!GV) {
GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, nullptr, GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, nullptr,
Name, nullptr, GlobalVariable::NotThreadLocal, Name, nullptr, GlobalVariable::NotThreadLocal,
AddrSpace); AddrSpace);
} else { } else {
if (GVal->getType()->getElementType() != Ty) if (GV->getType()->getElementType() != Ty)
return Error(TyLoc, return Error(TyLoc,
"forward reference and definition of global have different types"); "forward reference and definition of global have different types");
GV = cast<GlobalVariable>(GVal);
// Move the forward-reference to the correct spot in the module. // Move the forward-reference to the correct spot in the module.
M->getGlobalList().splice(M->global_end(), M->getGlobalList(), GV); M->getGlobalList().splice(M->global_end(), M->getGlobalList(), GV);
} }

View File

@ -1,4 +0,0 @@
; RUN: not llvm-as %s -disable-output 2>&1 | grep "forward reference and definition of global have different types"
@a2 = alias void ()* @g2
@g2 = internal global i8 42