From 13d5c58951083fd44481974a2beb764914f20907 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 6 Apr 2016 02:06:40 +0000 Subject: [PATCH] AsmParser: Don't crash on unresolved !tbaa Instead of crashing, give a nice error. As a drive-by, fix the location associated with the errors for unresolved metadata (the location was off by one token). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265507 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLParser.cpp | 9 +++++---- test/Assembler/invalid-mdnode-badref.ll | 2 +- test/Assembler/missing-tbaa.ll | 11 +++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 test/Assembler/missing-tbaa.ll diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 3eb52ea2282..369dbb38f7c 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -100,9 +100,6 @@ void LLParser::restoreParsingState(const SlotMapping *Slots) { /// ValidateEndOfModule - Do final validity and sanity checks at the end of the /// module. bool LLParser::ValidateEndOfModule() { - for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++) - UpgradeInstWithTBAATag(InstsWithTBAATag[I]); - // Handle any function attribute group forward references. for (std::map >::iterator I = ForwardRefAttrGroups.begin(), E = ForwardRefAttrGroups.end(); @@ -205,6 +202,9 @@ bool LLParser::ValidateEndOfModule() { N.second->resolveCycles(); } + for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++) + UpgradeInstWithTBAATag(InstsWithTBAATag[I]); + // Look for intrinsic functions and CallInst that need to be upgraded for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) UpgradeCallsToIntrinsic(&*FI++); // must be post-increment, as we remove @@ -601,6 +601,7 @@ bool LLParser::ParseMDString(MDString *&Result) { // ::= '!' MDNodeNumber bool LLParser::ParseMDNodeID(MDNode *&Result) { // !{ ..., !42, ... } + LocTy IDLoc = Lex.getLoc(); unsigned MID = 0; if (ParseUInt32(MID)) return true; @@ -613,7 +614,7 @@ bool LLParser::ParseMDNodeID(MDNode *&Result) { // Otherwise, create MDNode forward reference. auto &FwdRef = ForwardRefMDNodes[MID]; - FwdRef = std::make_pair(MDTuple::getTemporary(Context, None), Lex.getLoc()); + FwdRef = std::make_pair(MDTuple::getTemporary(Context, None), IDLoc); Result = FwdRef.first.get(); NumberedMetadata[MID].reset(Result); diff --git a/test/Assembler/invalid-mdnode-badref.ll b/test/Assembler/invalid-mdnode-badref.ll index cfa03e0b3c6..5c28ef05493 100644 --- a/test/Assembler/invalid-mdnode-badref.ll +++ b/test/Assembler/invalid-mdnode-badref.ll @@ -1,5 +1,5 @@ ; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s !named = !{!0} -; CHECK: [[@LINE+1]]:14: error: use of undefined metadata '!1' +; CHECK: [[@LINE+1]]:13: error: use of undefined metadata '!1' !0 = !{!0, !1} diff --git a/test/Assembler/missing-tbaa.ll b/test/Assembler/missing-tbaa.ll new file mode 100644 index 00000000000..38fe754b603 --- /dev/null +++ b/test/Assembler/missing-tbaa.ll @@ -0,0 +1,11 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +; Check that !tbaa upgrade doesn't crash on undefined metadata (it should give +; an error). + +define void @foo() { +entry: + store i8 undef, i8* undef, +; CHECK: :[[@LINE+1]]:10: error: use of undefined metadata '!1' + !tbaa !1 + unreachable +} -- 2.11.0