[llvm] b3ed72e - [MC][AsmParser] Remove "in directive" from diagnostics

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 14:04:33 PST 2022


Author: Fangrui Song
Date: 2022-12-01T22:04:27Z
New Revision: b3ed72ed48e69d919fe25973ceb06a456d8be450

URL: https://github.com/llvm/llvm-project/commit/b3ed72ed48e69d919fe25973ceb06a456d8be450
DIFF: https://github.com/llvm/llvm-project/commit/b3ed72ed48e69d919fe25973ceb06a456d8be450.diff

LOG: [MC][AsmParser] Remove "in directive" from diagnostics

This part is not useful (all the custom parsing deals with directives) and does
not appear in the majority of diagnostics.

While updating diagnostics, change "unexpected token" to more useful
diagnostics, e.g. "expected comma", "expected end of directive".

Added: 
    

Modified: 
    llvm/lib/MC/MCParser/ELFAsmParser.cpp
    llvm/test/MC/ELF/ARM/gnu-type-hash-diagnostics.s
    llvm/test/MC/ELF/bad-section.s
    llvm/test/MC/ELF/gnu-type-diagnostics.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index f17d3636ffe4c..a5981d15013f6 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -178,7 +178,7 @@ bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
       StringRef Name;
 
       if (getParser().parseIdentifier(Name))
-        return TokError("expected identifier in directive");
+        return TokError("expected identifier");
 
       if (getParser().discardLTOSymbol(Name)) {
         if (getLexer().is(AsmToken::EndOfStatement))
@@ -194,7 +194,7 @@ bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
         break;
 
       if (getLexer().isNot(AsmToken::Comma))
-        return TokError("unexpected token in directive");
+        return TokError("expected comma");
       Lex();
     }
   }
@@ -221,11 +221,11 @@ bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
 bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
   StringRef Name;
   if (getParser().parseIdentifier(Name))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
   MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
 
   if (getLexer().isNot(AsmToken::Comma))
-    return TokError("unexpected token in directive");
+    return TokError("expected comma");
   Lex();
 
   const MCExpr *Expr;
@@ -233,7 +233,7 @@ bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
     return true;
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
-    return TokError("unexpected token in directive");
+    return TokError("unexpected token");
   Lex();
 
   getStreamer().emitELFSize(Sym, Expr);
@@ -417,7 +417,7 @@ bool ELFAsmParser::maybeParseSectionType(StringRef &TypeName) {
     TypeName = getTok().getString();
     Lex();
   } else if (getParser().parseIdentifier(TypeName))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
   return false;
 }
 
@@ -485,7 +485,7 @@ bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) {
   Lex();
   StringRef UniqueStr;
   if (getParser().parseIdentifier(UniqueStr))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
   if (UniqueStr != "unique")
     return TokError("expected 'unique'");
   if (L.isNot(AsmToken::Comma))
@@ -526,7 +526,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
   StringRef SectionName;
 
   if (ParseSectionName(SectionName))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   StringRef TypeName;
   int64_t Size = 0;
@@ -567,7 +567,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
 
     if (getLexer().isNot(AsmToken::String)) {
       if (getLexer().isNot(AsmToken::Hash))
-        return TokError("expected string in directive");
+        return TokError("expected string");
       extraFlags = parseSunStyleSectionFlags();
     } else {
       StringRef FlagsStr = getTok().getStringContents();
@@ -596,7 +596,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
       if (Group)
         return TokError("Group section must specify the type");
       if (L.isNot(AsmToken::EndOfStatement))
-        return TokError("unexpected token in directive");
+        return TokError("expected end of directive");
     }
 
     if (Mergeable)
@@ -614,7 +614,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
 
 EndStmt:
   if (getLexer().isNot(AsmToken::EndOfStatement))
-    return TokError("unexpected token in directive");
+    return TokError("expected end of directive");
   Lex();
 
   unsigned Type = ELF::SHT_PROGBITS;
@@ -746,7 +746,7 @@ static MCSymbolAttr MCAttrForString(StringRef Type) {
 bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
   StringRef Name;
   if (getParser().parseIdentifier(Name))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   // Handle the identifier as the key symbol.
   MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
@@ -779,14 +779,14 @@ bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
 
   StringRef Type;
   if (getParser().parseIdentifier(Type))
-    return TokError("expected symbol type in directive");
+    return TokError("expected symbol type");
 
   MCSymbolAttr Attr = MCAttrForString(Type);
   if (Attr == MCSA_Invalid)
-    return Error(TypeLoc, "unsupported attribute in '.type' directive");
+    return Error(TypeLoc, "unsupported attribute");
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
-    return TokError("unexpected token in '.type' directive");
+    return TokError("expected end of directive");
   Lex();
 
   getStreamer().emitSymbolAttribute(Sym, Attr);
@@ -798,14 +798,14 @@ bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
 ///  ::= .ident string
 bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
   if (getLexer().isNot(AsmToken::String))
-    return TokError("unexpected token in '.ident' directive");
+    return TokError("expected string");
 
   StringRef Data = getTok().getIdentifier();
 
   Lex();
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
-    return TokError("unexpected token in '.ident' directive");
+    return TokError("expected end of directive");
   Lex();
 
   getStreamer().emitIdent(Data);
@@ -817,7 +817,7 @@ bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
 bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
   StringRef OriginalName, Name, Action;
   if (getParser().parseIdentifier(OriginalName))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("expected a comma");
@@ -832,7 +832,7 @@ bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
   getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
 
   if (getParser().parseIdentifier(Name))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   if (!Name.contains('@'))
     return TokError("expected a '@' in the name");
@@ -853,7 +853,7 @@ bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
 ///  ::= .version string
 bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
   if (getLexer().isNot(AsmToken::String))
-    return TokError("unexpected token in '.version' directive");
+    return TokError("expected string");
 
   StringRef Data = getTok().getIdentifier();
 
@@ -880,7 +880,7 @@ bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
 
   StringRef AliasName;
   if (getParser().parseIdentifier(AliasName))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("expected a comma");
@@ -889,7 +889,7 @@ bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
 
   StringRef Name;
   if (getParser().parseIdentifier(Name))
-    return TokError("expected identifier in directive");
+    return TokError("expected identifier");
 
   MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
 
@@ -907,7 +907,7 @@ bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
   }
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
-    return TokError("unexpected token in directive");
+    return TokError("expected end of directive");
 
   Lex();
 

diff  --git a/llvm/test/MC/ELF/ARM/gnu-type-hash-diagnostics.s b/llvm/test/MC/ELF/ARM/gnu-type-hash-diagnostics.s
index 7dc656d5a4d76..9a9c7469906c2 100644
--- a/llvm/test/MC/ELF/ARM/gnu-type-hash-diagnostics.s
+++ b/llvm/test/MC/ELF/ARM/gnu-type-hash-diagnostics.s
@@ -3,7 +3,7 @@
 	.syntax unified
 
 	.type TYPE #32
-// CHECK: error: expected symbol type in directive
+// CHECK: error: expected symbol type
 // CHECK: .type TYPE #32
 // CHECK:             ^
 

diff  --git a/llvm/test/MC/ELF/bad-section.s b/llvm/test/MC/ELF/bad-section.s
index 73d89ce765a4a..3697fa126c084 100644
--- a/llvm/test/MC/ELF/bad-section.s
+++ b/llvm/test/MC/ELF/bad-section.s
@@ -1,7 +1,7 @@
 // RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o /dev/null 2>%t
 // RUN: FileCheck --input-file=%t %s
 
-// CHECK: error: unexpected token in directive
+// CHECK: :[[#@LINE+5]]:15: error: expected end of directive
 // CHECK: .section "foo"-bar
 
 // test that we don't accept this, as gas doesn't.

diff  --git a/llvm/test/MC/ELF/gnu-type-diagnostics.s b/llvm/test/MC/ELF/gnu-type-diagnostics.s
index df87d6df082e6..23c144fee1db8 100644
--- a/llvm/test/MC/ELF/gnu-type-diagnostics.s
+++ b/llvm/test/MC/ELF/gnu-type-diagnostics.s
@@ -1,12 +1,12 @@
 // RUN: not llvm-mc -triple i686-elf -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
 
 	.type TYPE FUNC
-// CHECK: error: unsupported attribute in '.type' directive
+// CHECK: error: unsupported attribute
 // CHECK: .type TYPE FUNC
 // CHECK:            ^
 
 	.type type stt_func
-// CHECK: error: unsupported attribute in '.type' directive
+// CHECK: error: unsupported attribute
 // CHECK: .type type stt_func
 // CHECK:            ^
 


        


More information about the llvm-commits mailing list