From 5d2d1f29e16d258dcfaa39eaed7c407c4085afa1 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 19 Jan 2015 23:32:36 +0000 Subject: [PATCH] AsmParser: Fix error location for missing fields git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226524 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLParser.cpp | 20 ++++++++++--------- lib/AsmParser/LLParser.h | 3 ++- .../invalid-mdlocation-missing-scope-2.ll | 4 ++++ .../invalid-mdlocation-missing-scope.ll | 4 ++++ 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 test/Assembler/invalid-mdlocation-missing-scope-2.ll create mode 100644 test/Assembler/invalid-mdlocation-missing-scope.ll diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 7696f537840..ff313ce2d74 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2953,12 +2953,13 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) { } template -bool LLParser::ParseMDFieldsImpl(ParserTy parseField) { +bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) { assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name"); Lex.Lex(); if (ParseToken(lltok::lparen, "expected '(' here")) return true; + ClosingLoc = Lex.getLoc(); if (EatIfPresent(lltok::rparen)) return false; @@ -2970,6 +2971,7 @@ bool LLParser::ParseMDFieldsImpl(ParserTy parseField) { return true; } while (EatIfPresent(lltok::comma)); + ClosingLoc = Lex.getLoc(); return ParseToken(lltok::rparen, "expected ')' here"); } @@ -3003,18 +3005,18 @@ bool LLParser::ParseMDLocation(MDNode *&Result, bool IsDistinct) { MDUnsignedField column(0, ~0u >> 16); MDField scope; MDField inlinedAt; + LocTy Loc; if (ParseMDFieldsImpl([&]() -> bool { - PARSE_MD_FIELD(line); - PARSE_MD_FIELD(column); - PARSE_MD_FIELD(scope); - PARSE_MD_FIELD(inlinedAt); - return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); - })) + PARSE_MD_FIELD(line); + PARSE_MD_FIELD(column); + PARSE_MD_FIELD(scope); + PARSE_MD_FIELD(inlinedAt); + return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); + }, Loc)) return true; if (!scope.Seen) - return TokError("missing required field 'scope'"); - + return Error(Loc, "missing required field 'scope'"); auto get = (IsDistinct ? MDLocation::getDistinct : MDLocation::get); Result = get(Context, line.Val, column.Val, scope.Val, inlinedAt.Val); return false; diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index b1f94c237a9..8175fbd9352 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -421,7 +421,8 @@ namespace llvm { bool ParseMDField(LocTy Loc, StringRef Name, MDUnsignedField &Result); bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result); - template bool ParseMDFieldsImpl(ParserTy parseField); + template + bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc); bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false); bool ParseMDLocation(MDNode *&Result, bool IsDistinct); diff --git a/test/Assembler/invalid-mdlocation-missing-scope-2.ll b/test/Assembler/invalid-mdlocation-missing-scope-2.ll new file mode 100644 index 00000000000..3b267c9199b --- /dev/null +++ b/test/Assembler/invalid-mdlocation-missing-scope-2.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s + +; CHECK: :[[@LINE+1]]:25: error: missing required field 'scope' +!0 = !MDLocation(line: 7) diff --git a/test/Assembler/invalid-mdlocation-missing-scope.ll b/test/Assembler/invalid-mdlocation-missing-scope.ll new file mode 100644 index 00000000000..87f41b31799 --- /dev/null +++ b/test/Assembler/invalid-mdlocation-missing-scope.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s + +; CHECK: :[[@LINE+1]]:18: error: missing required field 'scope' +!0 = !MDLocation() -- 2.34.1