From e416515115337648ae6e694db22fe4d8196e6155 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 28 Apr 2023 00:52:33 -0700 Subject: [PATCH] MC: Use parseEOL The diagnostics have changed from "unexpected token" to clearer "expected newline" --- llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 4 ++-- llvm/lib/MC/MCParser/MasmParser.cpp | 19 +++++++++---------- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 2 +- llvm/test/MC/ARM/directive_parsing.s | 2 +- llvm/test/MC/MachO/ARM/build-version-diagnostics.s | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp index 67311f1..7c39004 100644 --- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp @@ -1130,7 +1130,7 @@ bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc, if (isSDKVersionToken(getLexer().getTok()) && parseSDKVersion(SDKVersion)) return true; - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(Twine(" in '") + Directive + "' directive"); Triple::OSType ExpectedOS = getOSTypeFromMCVM(Type); @@ -1191,7 +1191,7 @@ bool DarwinAsmParser::parseBuildVersion(StringRef Directive, SMLoc Loc) { if (isSDKVersionToken(getLexer().getTok()) && parseSDKVersion(SDKVersion)) return true; - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in '.build_version' directive"); Triple::OSType ExpectedOS diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp index 211a10e..d522b77 100644 --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -4537,7 +4537,7 @@ bool MasmParser::parseDirectiveStruct(StringRef Directive, "' directive; expected none or NONUNIQUE"); } - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in '" + Twine(Directive) + "' directive"); StructInProgress.emplace_back(Name, DirKind == DK_UNION, AlignmentValue); @@ -4559,7 +4559,7 @@ bool MasmParser::parseDirectiveNestedStruct(StringRef Directive, Name = getTok().getIdentifier(); parseToken(AsmToken::Identifier); } - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in '" + Twine(Directive) + "' directive"); // Reserve space to ensure Alignment doesn't get invalidated when @@ -4585,7 +4585,7 @@ bool MasmParser::parseDirectiveEnds(StringRef Name, SMLoc NameLoc) { Structure.Size, std::min(Structure.Alignment, Structure.AlignmentSize)); Structs[Name.lower()] = Structure; - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in ENDS directive"); return false; @@ -4597,7 +4597,7 @@ bool MasmParser::parseDirectiveNestedEnds() { if (StructInProgress.size() == 1) return TokError("missing name in top-level ENDS directive"); - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in nested ENDS directive"); StructInfo Structure = StructInProgress.pop_back_val(); @@ -4669,7 +4669,7 @@ bool MasmParser::parseDirectiveOrg() { SMLoc OffsetLoc = Lexer.getLoc(); if (checkForValidSection() || parseExpression(Offset)) return true; - if (parseToken(AsmToken::EndOfStatement)) + if (parseEOL()) return addErrorSuffix(" in 'org' directive"); if (StructInProgress.empty()) { @@ -4738,10 +4738,9 @@ bool MasmParser::parseDirectiveAlign() { if (getTok().is(AsmToken::EndOfStatement)) { return Warning(AlignmentLoc, "align directive with no operand is ignored") && - parseToken(AsmToken::EndOfStatement); + parseEOL(); } - if (parseAbsoluteExpression(Alignment) || - parseToken(AsmToken::EndOfStatement)) + if (parseAbsoluteExpression(Alignment) || parseEOL()) return addErrorSuffix(" in align directive"); // Always emit an alignment here even if we throw an error. @@ -4764,7 +4763,7 @@ bool MasmParser::parseDirectiveAlign() { /// parseDirectiveEven /// ::= even bool MasmParser::parseDirectiveEven() { - if (parseToken(AsmToken::EndOfStatement) || emitAlignTo(2)) + if (parseEOL() || emitAlignTo(2)) return addErrorSuffix(" in even directive"); return false; @@ -5482,7 +5481,7 @@ bool MasmParser::parseDirectiveCFIStartProc() { if (!parseOptionalToken(AsmToken::EndOfStatement)) { if (check(parseIdentifier(Simple) || Simple != "simple", "unexpected token") || - parseToken(AsmToken::EndOfStatement)) + parseEOL()) return addErrorSuffix(" in '.cfi_startproc' directive"); } diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index ace2891..bde60372 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -11957,7 +11957,7 @@ bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { Offset = CE->getValue(); } - if (Parser.parseToken(AsmToken::EndOfStatement)) + if (Parser.parseEOL()) return true; getTargetStreamer().emitSetFP(static_cast(FPReg), diff --git a/llvm/test/MC/ARM/directive_parsing.s b/llvm/test/MC/ARM/directive_parsing.s index 90d15ef..a803984 100644 --- a/llvm/test/MC/ARM/directive_parsing.s +++ b/llvm/test/MC/ARM/directive_parsing.s @@ -63,7 +63,7 @@ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .personality __gxx_personality_v0 @ EOL COMMENET -// CHECK: [[@LINE+1]]:28: error: unexpected token +// CHECK: [[#@LINE+1]]:28: error: expected newline .setfp fp, sp, #0 $ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .setfp fp, sp, #0 @ EOL COMMENT diff --git a/llvm/test/MC/MachO/ARM/build-version-diagnostics.s b/llvm/test/MC/MachO/ARM/build-version-diagnostics.s index 31aa87a..15687c2 100644 --- a/llvm/test/MC/MachO/ARM/build-version-diagnostics.s +++ b/llvm/test/MC/MachO/ARM/build-version-diagnostics.s @@ -53,4 +53,4 @@ // CHECK: build-version-diagnostics.s:[[@LINE-1]]:25: error: invalid OS update version number .build_version ios,10,0,0, -// CHECK: build-version-diagnostics.s:[[@LINE-1]]:26: error: unexpected token in '.build_version' directive +// CHECK: build-version-diagnostics.s:[[#@LINE-1]]:26: error: expected newline in '.build_version' directive -- 2.7.4