[PATCH] D31674: [AsmParser]Emit an error if a macro has two (or more) parameters sharing the same name
coby via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 4 11:25:52 PDT 2017
coby created this revision.
Introducing a new error to macro parameters' parsing:
currently, llvm-mc won't complain if a macro have two (or more) named params with the same name.
this behavior is false, as there's no merit in having some params sharing a name.
now, instead of tolerate such a phenomena - emit an appropriate error.
Repository:
rL LLVM
https://reviews.llvm.org/D31674
Files:
lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/macro-duplicate-params-names-err.s
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -3874,6 +3874,12 @@
if (parseIdentifier(Parameter.Name))
return TokError("expected identifier in '.macro' directive");
+ // Emit an error if two (or more) named parameters share the same name
+ for (const MCAsmMacroParameter& CurrParam : Parameters)
+ if (CurrParam.Name.equals(Parameter.Name))
+ return TokError("macro '" + Name + "' has at least two parameters"
+ " named '" + Parameter.Name + "'");
+
if (Lexer.is(AsmToken::Colon)) {
Lex(); // consume ':'
Index: test/MC/AsmParser/macro-duplicate-params-names-err.s
===================================================================
--- test/MC/AsmParser/macro-duplicate-params-names-err.s
+++ test/MC/AsmParser/macro-duplicate-params-names-err.s
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -triple x86_64-unknown-unknown %s 2> %t
+// RUN: FileCheck < %t %s
+
+.macro M a a
+ nop
+.endm
+
+// CHECK: macro 'M' has at least two parameters named 'a'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31674.94096.patch
Type: text/x-patch
Size: 1162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/ad10cbdf/attachment.bin>
More information about the llvm-commits
mailing list