[llvm] r226524 - AsmParser: Fix error location for missing fields
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 19 15:32:36 PST 2015
Author: dexonsmith
Date: Mon Jan 19 17:32:36 2015
New Revision: 226524
URL: http://llvm.org/viewvc/llvm-project?rev=226524&view=rev
Log:
AsmParser: Fix error location for missing fields
Added:
llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope-2.ll
llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope.ll
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=226524&r1=226523&r2=226524&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jan 19 17:32:36 2015
@@ -2953,12 +2953,13 @@ bool LLParser::ParseMDField(LocTy Loc, S
}
template <class ParserTy>
-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(ParserT
return true;
} while (EatIfPresent(lltok::comma));
+ ClosingLoc = Lex.getLoc();
return ParseToken(lltok::rparen, "expected ')' here");
}
@@ -3003,18 +3005,18 @@ bool LLParser::ParseMDLocation(MDNode *&
MDUnsignedField<uint32_t> 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;
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=226524&r1=226523&r2=226524&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Mon Jan 19 17:32:36 2015
@@ -421,7 +421,8 @@ namespace llvm {
bool ParseMDField(LocTy Loc, StringRef Name,
MDUnsignedField<uint32_t> &Result);
bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result);
- template <class ParserTy> bool ParseMDFieldsImpl(ParserTy parseField);
+ template <class ParserTy>
+ bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
bool ParseMDLocation(MDNode *&Result, bool IsDistinct);
Added: llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope-2.ll?rev=226524&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope-2.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope-2.ll Mon Jan 19 17:32:36 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:25: error: missing required field 'scope'
+!0 = !MDLocation(line: 7)
Added: llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope.ll?rev=226524&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdlocation-missing-scope.ll Mon Jan 19 17:32:36 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:18: error: missing required field 'scope'
+!0 = !MDLocation()
More information about the llvm-commits
mailing list