mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-01 14:58:18 +00:00
[AsmParser] Gracefully handle non-existent GV summary reference
If the module summary references a global variable that does not exist, throw a nice error instead of asserting. Fixes https://github.com/llvm/llvm-project/issues/74726.
This commit is contained in:
parent
04c4566ca1
commit
dfd36aa70e
@ -407,9 +407,10 @@ namespace llvm {
|
||||
std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>
|
||||
&ResByArg);
|
||||
bool parseArgs(std::vector<uint64_t> &Args);
|
||||
void addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
|
||||
bool addGlobalValueToIndex(std::string Name, GlobalValue::GUID,
|
||||
GlobalValue::LinkageTypes Linkage, unsigned ID,
|
||||
std::unique_ptr<GlobalValueSummary> Summary);
|
||||
std::unique_ptr<GlobalValueSummary> Summary,
|
||||
LocTy Loc);
|
||||
bool parseOptionalAllocs(std::vector<AllocInfo> &Allocs);
|
||||
bool parseMemProfs(std::vector<MIBInfo> &MIBs);
|
||||
bool parseAllocType(uint8_t &AllocType);
|
||||
|
@ -8622,9 +8622,9 @@ static void resolveFwdRef(ValueInfo *Fwd, ValueInfo &Resolved) {
|
||||
|
||||
/// Stores the given Name/GUID and associated summary into the Index.
|
||||
/// Also updates any forward references to the associated entry ID.
|
||||
void LLParser::addGlobalValueToIndex(
|
||||
bool LLParser::addGlobalValueToIndex(
|
||||
std::string Name, GlobalValue::GUID GUID, GlobalValue::LinkageTypes Linkage,
|
||||
unsigned ID, std::unique_ptr<GlobalValueSummary> Summary) {
|
||||
unsigned ID, std::unique_ptr<GlobalValueSummary> Summary, LocTy Loc) {
|
||||
// First create the ValueInfo utilizing the Name or GUID.
|
||||
ValueInfo VI;
|
||||
if (GUID != 0) {
|
||||
@ -8634,7 +8634,9 @@ void LLParser::addGlobalValueToIndex(
|
||||
assert(!Name.empty());
|
||||
if (M) {
|
||||
auto *GV = M->getNamedValue(Name);
|
||||
assert(GV);
|
||||
if (!GV)
|
||||
return error(Loc, "Reference to undefined global \"" + Name + "\"");
|
||||
|
||||
VI = Index->getOrInsertValueInfo(GV);
|
||||
} else {
|
||||
assert(
|
||||
@ -8682,6 +8684,8 @@ void LLParser::addGlobalValueToIndex(
|
||||
NumberedValueInfos.resize(ID + 1);
|
||||
NumberedValueInfos[ID] = VI;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// parseSummaryIndexFlags
|
||||
@ -8728,6 +8732,7 @@ bool LLParser::parseGVEntry(unsigned ID) {
|
||||
parseToken(lltok::lparen, "expected '(' here"))
|
||||
return true;
|
||||
|
||||
LocTy Loc = Lex.getLoc();
|
||||
std::string Name;
|
||||
GlobalValue::GUID GUID = 0;
|
||||
switch (Lex.getKind()) {
|
||||
@ -8757,9 +8762,8 @@ bool LLParser::parseGVEntry(unsigned ID) {
|
||||
// an external definition. We pass ExternalLinkage since that is only
|
||||
// used when the GUID must be computed from Name, and in that case
|
||||
// the symbol must have external linkage.
|
||||
addGlobalValueToIndex(Name, GUID, GlobalValue::ExternalLinkage, ID,
|
||||
nullptr);
|
||||
return false;
|
||||
return addGlobalValueToIndex(Name, GUID, GlobalValue::ExternalLinkage, ID,
|
||||
nullptr, Loc);
|
||||
}
|
||||
|
||||
// Have a list of summaries
|
||||
@ -8800,6 +8804,7 @@ bool LLParser::parseGVEntry(unsigned ID) {
|
||||
/// [',' OptionalRefs]? ')'
|
||||
bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
unsigned ID) {
|
||||
LocTy Loc = Lex.getLoc();
|
||||
assert(Lex.getKind() == lltok::kw_function);
|
||||
Lex.Lex();
|
||||
|
||||
@ -8876,10 +8881,9 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
|
||||
FS->setModulePath(ModulePath);
|
||||
|
||||
addGlobalValueToIndex(Name, GUID, (GlobalValue::LinkageTypes)GVFlags.Linkage,
|
||||
ID, std::move(FS));
|
||||
|
||||
return false;
|
||||
return addGlobalValueToIndex(Name, GUID,
|
||||
(GlobalValue::LinkageTypes)GVFlags.Linkage, ID,
|
||||
std::move(FS), Loc);
|
||||
}
|
||||
|
||||
/// VariableSummary
|
||||
@ -8887,6 +8891,7 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
/// [',' OptionalRefs]? ')'
|
||||
bool LLParser::parseVariableSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
unsigned ID) {
|
||||
LocTy Loc = Lex.getLoc();
|
||||
assert(Lex.getKind() == lltok::kw_variable);
|
||||
Lex.Lex();
|
||||
|
||||
@ -8934,10 +8939,9 @@ bool LLParser::parseVariableSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
GS->setModulePath(ModulePath);
|
||||
GS->setVTableFuncs(std::move(VTableFuncs));
|
||||
|
||||
addGlobalValueToIndex(Name, GUID, (GlobalValue::LinkageTypes)GVFlags.Linkage,
|
||||
ID, std::move(GS));
|
||||
|
||||
return false;
|
||||
return addGlobalValueToIndex(Name, GUID,
|
||||
(GlobalValue::LinkageTypes)GVFlags.Linkage, ID,
|
||||
std::move(GS), Loc);
|
||||
}
|
||||
|
||||
/// AliasSummary
|
||||
@ -8984,10 +8988,9 @@ bool LLParser::parseAliasSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
AS->setAliasee(AliaseeVI, Summary);
|
||||
}
|
||||
|
||||
addGlobalValueToIndex(Name, GUID, (GlobalValue::LinkageTypes)GVFlags.Linkage,
|
||||
ID, std::move(AS));
|
||||
|
||||
return false;
|
||||
return addGlobalValueToIndex(Name, GUID,
|
||||
(GlobalValue::LinkageTypes)GVFlags.Linkage, ID,
|
||||
std::move(AS), Loc);
|
||||
}
|
||||
|
||||
/// Flag
|
||||
|
4
llvm/test/Assembler/summary-parsing-error.ll
Normal file
4
llvm/test/Assembler/summary-parsing-error.ll
Normal file
@ -0,0 +1,4 @@
|
||||
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK: Reference to undefined global "does_not_exist"
|
||||
^0 = gv: (name: "does_not_exist")
|
Loading…
x
Reference in New Issue
Block a user