[PATCH] D30657: Handle EOL preprocessor comments for ELFAsmParser symbol attr directives

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 08:03:04 PST 2017


tejohnson created this revision.
Herald added subscribers: mehdi_amini, aemerson.

There is already handling in the MCAsmParser for end-of-line comments
starting with "#". This is handled in MCAsmParser::parseOptionalToken,
which is invoked by MCAsmParser::parseMany which parses comma-separated
lists. However, the ELFAsmParser was not invoking this handling.

I found this issue when adding .global/.globl to the set of directives
handled by the ELFAsmParser for a follow up fix, which caused the
test/MC/AsmParser/AArch64/directive-parse-err.s to fail to parse:

  .global a2                   # EOL COMMENT

This is because the ELFAsmParser was then invoked to handle parsing
of this directive, instead of falling through to the invocation of
AsmParser::parseDirectiveAscii (which invokes parseMany) in
AsmParser::parseStatement.

In this patch I add a test case to show the failure for a symbol
directive already processed by ELFAsmParser (.hidden), and modify
the parser to invoke parseMany.


https://reviews.llvm.org/D30657

Files:
  lib/MC/MCParser/ELFAsmParser.cpp
  test/MC/AsmParser/AArch64/directive-parse-err.s


Index: test/MC/AsmParser/AArch64/directive-parse-err.s
===================================================================
--- test/MC/AsmParser/AArch64/directive-parse-err.s
+++ test/MC/AsmParser/AArch64/directive-parse-err.s
@@ -1,5 +1,5 @@
 // RUN: not llvm-mc -triple aarch64-unknown-unknown %s 2>&1 | FileCheck %s
-// RUN: not llvm-mc -triple aarch64-unknown-unknown %s 2>&1 | grep "error:" | count 60
+// RUN: not llvm-mc -triple aarch64-unknown-unknown %s 2>&1 | grep "error:" | count 61
 
 	// CHECK: [[@LINE+1]]:19: error: unexpected token in '.equ' directive
 	.equ   ident1, 0 $
@@ -205,6 +205,10 @@
 	.global a2                   $
 	// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
 	.global a2                   # EOL COMMENT
+	// CHECK: [[@LINE+1]]:31: error: unexpected token
+	.hidden a1                   $
+	// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
+	.hidden a1                   # EOL COMMENT
 	// CHECK: [[@LINE+1]]:31: error: unexpected token in directive
 	.lazy_reference a3           $
 	// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
Index: lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- lib/MC/MCParser/ELFAsmParser.cpp
+++ lib/MC/MCParser/ELFAsmParser.cpp
@@ -174,27 +174,18 @@
     .Case(".protected", MCSA_Protected)
     .Default(MCSA_Invalid);
   assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
-  if (getLexer().isNot(AsmToken::EndOfStatement)) {
-    while (true) {
-      StringRef Name;
-
-      if (getParser().parseIdentifier(Name))
-        return TokError("expected identifier in directive");
-
-      MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
-
-      getStreamer().EmitSymbolAttribute(Sym, Attr);
-
-      if (getLexer().is(AsmToken::EndOfStatement))
-        break;
+  auto parseOp = [&]() -> bool {
+    StringRef Name;
+    if (getParser().parseIdentifier(Name))
+      return true;
+    MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
+    getStreamer().EmitSymbolAttribute(Sym, Attr);
+    return false;
+  };
 
-      if (getLexer().isNot(AsmToken::Comma))
-        return TokError("unexpected token in directive");
-      Lex();
-    }
-  }
+  if (parseMany(parseOp))
+    return addErrorSuffix(" in '" + Twine(Directive) + "' directive");
 
-  Lex();
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30657.90706.patch
Type: text/x-patch
Size: 2323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170306/67b2c6a5/attachment.bin>


More information about the llvm-commits mailing list