[llvm] 8c911f8 - [ARM][MC] Change EndOfStatement "unexpected tokens in .xxx directive " to "expected newline"

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 5 14:54:03 PDT 2022


Author: Fangrui Song
Date: 2022-06-05T14:53:59-07:00
New Revision: 8c911f8e9ae824d78930ac4fdc9ad4084a9098f2

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

LOG: [ARM][MC] Change EndOfStatement "unexpected tokens in .xxx directive " to "expected newline"

The directive name is not useful because the next line replicates the error line
which includes the directive. The prevailing style uses "expected newline".

Added: 
    

Modified: 
    llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
    llvm/test/MC/ARM/directive-thumb_func.s
    llvm/test/MC/ARM/directive-tlsdescseq-diagnostics.s
    llvm/test/MC/ARM/directive_parsing.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 899643fcae720..6b9058798728e 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11162,8 +11162,7 @@ bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
 /// parseDirectiveThumb
 ///  ::= .thumb
 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive") ||
-      check(!hasThumb(), L, "target does not support Thumb mode"))
+  if (parseEOL() || check(!hasThumb(), L, "target does not support Thumb mode"))
     return true;
 
   if (!isThumb())
@@ -11176,8 +11175,7 @@ bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
 /// parseDirectiveARM
 ///  ::= .arm
 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive") ||
-      check(!hasARM(), L, "target does not support ARM mode"))
+  if (parseEOL() || check(!hasARM(), L, "target does not support ARM mode"))
     return true;
 
   if (isThumb())
@@ -11216,15 +11214,13 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
           Parser.getTok().getIdentifier());
       getParser().getStreamer().emitThumbFunc(Func);
       Parser.Lex();
-      if (parseToken(AsmToken::EndOfStatement,
-                     "unexpected token in '.thumb_func' directive"))
+      if (parseEOL())
         return true;
       return false;
     }
   }
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.thumb_func' directive"))
+  if (parseEOL())
     return true;
 
   // .thumb_func implies .thumb
@@ -11253,7 +11249,7 @@ bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
             "'.syntax divided' arm assembly not supported") ||
       check(Mode != "unified" && Mode != "UNIFIED", L,
             "unrecognized syntax mode in .syntax directive") ||
-      parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+      parseEOL())
     return true;
 
   // TODO tell the MC streamer the mode
@@ -11275,7 +11271,7 @@ bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
   }
   Parser.Lex();
 
-  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseEOL())
     return true;
 
   if (Val == 16) {
@@ -11455,8 +11451,7 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
     Parser.Lex();
   }
 
-  if (Parser.parseToken(AsmToken::EndOfStatement,
-                        "unexpected token in '.eabi_attribute' directive"))
+  if (Parser.parseEOL())
     return true;
 
   if (IsIntegerValue && IsStringValue) {
@@ -11512,8 +11507,7 @@ bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
 /// parseDirectiveFnStart
 ///  ::= .fnstart
 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.fnstart' directive"))
+  if (parseEOL())
     return true;
 
   if (UC.hasFnStart()) {
@@ -11534,8 +11528,7 @@ bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
 /// parseDirectiveFnEnd
 ///  ::= .fnend
 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.fnend' directive"))
+  if (parseEOL())
     return true;
   // Check the ordering of unwind directives
   if (!UC.hasFnStart())
@@ -11551,8 +11544,7 @@ bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
 /// parseDirectiveCantUnwind
 ///  ::= .cantunwind
 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.cantunwind' directive"))
+  if (parseEOL())
     return true;
 
   UC.recordCantUnwind(L);
@@ -11587,8 +11579,7 @@ bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
   StringRef Name(Parser.getTok().getIdentifier());
   Parser.Lex();
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.personality' directive"))
+  if (parseEOL())
     return true;
 
   UC.recordPersonality(L);
@@ -11620,8 +11611,7 @@ bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
 /// parseDirectiveHandlerData
 ///  ::= .handlerdata
 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.handlerdata' directive"))
+  if (parseEOL())
     return true;
 
   UC.recordHandlerData(L);
@@ -11719,8 +11709,7 @@ bool ARMAsmParser::parseDirectivePad(SMLoc L) {
   if (!CE)
     return Error(ExLoc, "pad offset must be an immediate");
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.pad' directive"))
+  if (parseEOL())
     return true;
 
   getTargetStreamer().emitPad(CE->getValue());
@@ -11741,8 +11730,7 @@ bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
   SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
 
   // Parse the register list
-  if (parseRegisterList(Operands, true, true) ||
-      parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseRegisterList(Operands, true, true) || parseEOL())
     return true;
   ARMOperand &Op = (ARMOperand &)*Operands[0];
   if (!IsVector && !Op.isRegList())
@@ -11825,7 +11813,7 @@ bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
 /// parseDirectiveLtorg
 ///  ::= .ltorg | .pool
 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
-  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseEOL())
     return true;
   getTargetStreamer().emitCurrentConstantPool();
   return false;
@@ -11834,7 +11822,7 @@ bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
   const MCSection *Section = getStreamer().getCurrentSectionOnly();
 
-  if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseEOL())
     return true;
 
   if (!Section) {
@@ -11859,9 +11847,7 @@ bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
 
   const MCExpr *IndexExpression;
   SMLoc IndexLoc = Parser.getTok().getLoc();
-  if (Parser.parseExpression(IndexExpression) ||
-      parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.personalityindex' directive")) {
+  if (Parser.parseExpression(IndexExpression) || parseEOL()) {
     return true;
   }
 
@@ -11962,8 +11948,7 @@ bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
                             MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
   Lex();
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.tlsdescseq' directive"))
+  if (parseEOL())
     return true;
 
   getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
@@ -12004,8 +11989,7 @@ bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
     Offset = CE->getValue();
   }
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.movsp' directive"))
+  if (parseEOL())
     return true;
 
   getTargetStreamer().emitMovSP(SPReg, Offset);
@@ -12092,8 +12076,7 @@ bool ARMAsmParser::parseDirectiveSEHAllocStack(SMLoc L, bool Wide) {
 bool ARMAsmParser::parseDirectiveSEHSaveRegs(SMLoc L, bool Wide) {
   SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
 
-  if (parseRegisterList(Operands) ||
-      parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseRegisterList(Operands) || parseEOL())
     return true;
   ARMOperand &Op = (ARMOperand &)*Operands[0];
   if (!Op.isRegList())
@@ -12135,8 +12118,7 @@ bool ARMAsmParser::parseDirectiveSEHSaveSP(SMLoc L) {
 bool ARMAsmParser::parseDirectiveSEHSaveFRegs(SMLoc L) {
   SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
 
-  if (parseRegisterList(Operands) ||
-      parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
+  if (parseRegisterList(Operands) || parseEOL())
     return true;
   ARMOperand &Op = (ARMOperand &)*Operands[0];
   if (!Op.isDPRRegList())
@@ -12558,8 +12540,7 @@ bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
   SMLoc ExtLoc = Parser.getTok().getLoc();
   Lex();
 
-  if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.arch_extension' directive"))
+  if (parseEOL())
     return true;
 
   if (Name == "nocrypto") {

diff  --git a/llvm/test/MC/ARM/directive-thumb_func.s b/llvm/test/MC/ARM/directive-thumb_func.s
index e83901888358d..8aef5fbd46223 100644
--- a/llvm/test/MC/ARM/directive-thumb_func.s
+++ b/llvm/test/MC/ARM/directive-thumb_func.s
@@ -10,13 +10,13 @@
 no_suffix:
 	bx lr
 
+// CHECK-EABI: :[[#@LINE+3]]:14: error: expected newline
+// CHECK-EABI: 	.thumb_func suffix
+// CHECK-EABI:              ^
 	.thumb_func suffix
 suffix:
 	bx lr
 
-// CHECK-EABI: error: unexpected token in '.thumb_func' directive
-// CHECK-EABI: 	.thumb_func suffix
-// CHECK-EABI:              ^
 
 // CHECK-EABI-NOT: error: invalid instruction
 

diff  --git a/llvm/test/MC/ARM/directive-tlsdescseq-diagnostics.s b/llvm/test/MC/ARM/directive-tlsdescseq-diagnostics.s
index 0d33b5894fea9..f2b4fd504f843 100644
--- a/llvm/test/MC/ARM/directive-tlsdescseq-diagnostics.s
+++ b/llvm/test/MC/ARM/directive-tlsdescseq-diagnostics.s
@@ -12,16 +12,14 @@ missing_variable:
 	.type bad_expression,%function
 bad_expression:
 .tlsdescseq variable(tlsdesc)
-
-@ CHECK: error: unexpected token
+@ CHECK: :[[#@LINE-1]]:21: error: expected newline
 @ CHECK: 	.tlsdescseq variable(tlsdesc)
 @ CHECK:                            ^
 
 	.type trailing_garbage,%function
 trailing_garbage:
 .tlsdescseq variable,
-
-@ CHECK: error: unexpected token
+@ CHECK: :[[#@LINE-1]]:21: error: expected newline
 @ CHECK: 	.tlsdescseq variable,
 @ CHECK:                            ^
 

diff  --git a/llvm/test/MC/ARM/directive_parsing.s b/llvm/test/MC/ARM/directive_parsing.s
index c513abcc6bcc3..33793bfd54e75 100644
--- a/llvm/test/MC/ARM/directive_parsing.s
+++ b/llvm/test/MC/ARM/directive_parsing.s
@@ -15,24 +15,24 @@
 	.hword 0 @ EOL COMMENT
 
   .arch armv7-a
-// CHECK: [[@LINE+1]]:9: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:9: error: expected newline
 	.thumb $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
 	.thumb @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:7: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:7: error: expected newline
 	.arm $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
 	.arm @ EOL COMMENT		
-// CHECK: [[@LINE+1]]:14: error: unexpected token in '.thumb_func' directive
+// CHECK: :[[#@LINE+1]]:14: error: expected newline
 	.thumb_func $ 
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
 	.thumb_func @ EOL COMMENT
-// CHECK: [[@LINE+1]]:11: error: unexpected token in directive	
+// CHECK: :[[#@LINE+1]]:11: error: expected newline	
 	.code 16 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.code 16 @ EOL COMMENTS	
-// CHECK: [[@LINE+1]]:18: error: unexpected token in directive	
+// CHECK: :[[#@LINE+1]]:18: error: expected newline	
 	.syntax unified $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.syntax unified @ EOL COMMENT
@@ -42,23 +42,23 @@
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.unreq fred @ EOL COMMENTS
 	
-// CHECK: [[@LINE+1]]:18: error: unexpected token in '.fnstart' directive
+// CHECK: :[[#@LINE+1]]:18: error: expected newline
         .fnstart $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.fnstart @ EOL COMMENT
-// CHECK: [[@LINE+1]]:23: error: unexpected token in '.cantunwind' directive
+// CHECK: :[[#@LINE+1]]:23: error: expected newline
         .cantunwind   $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.cantunwind   @ EOL COMMENT	
 
 
-// CHECK: [[@LINE+1]]:18: error: unexpected token in '.fnend' directive
+// CHECK: :[[#@LINE+1]]:18: error: expected newline
         .fnend   $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.fnend   @ EOL COMMENT	
 
 	.fnstart
-// CHECK: [[@LINE+1]]:43: error: unexpected token in '.personality' directive
+// CHECK: :[[#@LINE+1]]:43: error: expected newline
         .personality __gxx_personality_v0 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
         .personality __gxx_personality_v0 @ EOL COMMENET
@@ -69,43 +69,43 @@
         .setfp  fp, sp, #0 @ EOL COMMENT
 
 
-// CHECK: [[@LINE+1]]:17: error: unexpected token in '.pad' directive
+// CHECK: :[[#@LINE+1]]:17: error: expected newline
         .pad #0 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
         .pad #0 @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:20: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:20: error: expected newline
         .save {r0} $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
         .save {r0} @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:21: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:21: error: expected newline
         .vsave {d0} $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
         .vsave {d0} @ EOL COMMENT
 	
 		
-// CHECK: [[@LINE+1]]:22: error: unexpected token in '.handlerdata' directive
+// CHECK: :[[#@LINE+1]]:22: error: expected newline
         .handlerdata $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
         .handlerdata @ EOL COMMENT
 
 	.fnend
 
-// CHECK: [[@LINE+1]]:9: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:9: error: expected newline
 	.ltorg $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.ltorg @ EOL COMMENT
-// CHECK: [[@LINE+1]]:8: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:8: error: expected newline
 	.pool $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.pool @ EOL COMMENT
-// CHECK: [[@LINE+1]]:8: error: unexpected token in directive
+// CHECK: :[[#@LINE+1]]:8: error: expected newline
 	.even $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.even	 @ EOL COMMENT	
 	.fnstart
-// CHECK: [[@LINE+1]]:22: error: unexpected token in '.personalityindex' directive
+// CHECK: :[[#@LINE+1]]:22: error: expected newline
 	.personalityindex 0 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.personalityindex 0 @ EOL COMMENT
@@ -117,18 +117,18 @@
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.unwind_raw 0, 0 @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:12: error: unexpected token in '.movsp' directive
+// CHECK: :[[#@LINE+1]]:12: error: expected newline
 	.movsp r0 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.movsp r1 @ EOL COMMENT
 	.fnend
 
-// CHECK: [[@LINE+1]]:21: error: unexpected token in '.arch_extension' directive
+// CHECK: :[[#@LINE+1]]:21: error: expected newline
 	.arch_extension mp $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
 	.arch_extension mp @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:21: error: unexpected token in '.arch_extension' directive
+// CHECK: :[[#@LINE+1]]:21: error: expected newline
 	.arch_extension mp $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
 	.arch_extension mp @ EOL COMMENT
@@ -136,12 +136,12 @@
         .type arm_func,%function
 arm_func:
         nop
-// CHECK: [[#@LINE+1]]:45: error: expected newline
+// CHECK: :[[#@LINE+1]]:45: error: expected newline
         .thumb_set alias_arm_func, arm_func $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:	
         .thumb_set alias_arm_func, arm_func @ EOL COMMENT
 
-// CHECK: [[@LINE+1]]:23: error: unexpected token in '.eabi_attribute' directive
+// CHECK: :[[#@LINE+1]]:23: error: expected newline
 	.eabi_attribute 0, 0 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:		
 	.eabi_attribute 0, 0 @ EOL COMMENT
@@ -164,7 +164,7 @@ arm_func:
 	.object_arch armv7 $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:		
 	.object_arch armv7 @ EOL COMMENT
-// CHECK: [[@LINE+1]]:23: error: unexpected token in '.tlsdescseq' directive
+// CHECK: :[[#@LINE+1]]:23: error: expected newline
 	.tlsdescseq variable $
 // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:		
 	.tlsdescseq variable @ EOL COMMENT


        


More information about the llvm-commits mailing list