[llvm-ml] Disallow '{' and '}' at the start of a statement
authorSergei Barannikov <barannikov88@gmail.com>
Mon, 23 Jan 2023 13:52:20 +0000 (16:52 +0300)
committerSergei Barannikov <barannikov88@gmail.com>
Wed, 25 Jan 2023 17:44:00 +0000 (20:44 +0300)
'{', '}' and (conditionally) '*' were allowed at the start of a
statement. This behavior was copied from AsmParser, where they were
added to support Hexagon bundles (braces) and BFP memory instructions
(the star).
MASM dialect is x86-specific and does not allow these symbols to be
used at the beginning of an instruction.

Worth noting that '{' is a valid first character in AT&T syntax
(e.g. "{vex} vpmadd52huq ..."); MASM variant is to omit the braces.

Reviewed By: epastor

Differential Revision: https://reviews.llvm.org/D142321

llvm/lib/MC/MCParser/MasmParser.cpp
llvm/test/tools/llvm-ml/label_errors.asm [new file with mode: 0644]

index f38dad417aed4e85089b58b527db9581dddb08b4..570dcab34fb9657b03e428fe2bed3e27a1e54ba6 100644 (file)
@@ -2125,20 +2125,6 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
     // Treat '.' as a valid identifier in this context.
     Lex();
     IDVal = ".";
-  } else if (Lexer.is(AsmToken::LCurly)) {
-    // Treat '{' as a valid identifier in this context.
-    Lex();
-    IDVal = "{";
-
-  } else if (Lexer.is(AsmToken::RCurly)) {
-    // Treat '}' as a valid identifier in this context.
-    Lex();
-    IDVal = "}";
-  } else if (Lexer.is(AsmToken::Star) &&
-             getTargetParser().starIsStartOfStatement()) {
-    // Accept '*' as a valid start of statement.
-    Lex();
-    IDVal = "*";
   } else if (Lexer.is(AsmToken::Real)) {
     // Treat ".<number>" as a valid identifier in this context.
     IDVal = getTok().getString();
diff --git a/llvm/test/tools/llvm-ml/label_errors.asm b/llvm/test/tools/llvm-ml/label_errors.asm
new file mode 100644 (file)
index 0000000..85d9569
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: not llvm-ml -filetype=s %s /Fo - 2>&1 \
+; RUN:   | FileCheck %s --implicit-check-not="{{[0-9]+:[0-9]+: error:}}"
+
+.code
+
+; These used to be valid label names.
+{: ; CHECK: [[@LINE]]:1: error: unexpected token at start of statement
+}: ; CHECK: [[@LINE]]:1: error: unexpected token at start of statement