[llvm] r299815 - [AsmParser]Emit an error if a macro has two (or more) parameters sharing the same name

Coby Tayree via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 8 13:29:04 PDT 2017


Author: coby
Date: Sat Apr  8 15:29:03 2017
New Revision: 299815

URL: http://llvm.org/viewvc/llvm-project?rev=299815&view=rev
Log:
[AsmParser]Emit an error if a macro has two (or more) parameters sharing the same name

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.

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

Added:
    llvm/trunk/test/MC/AsmParser/macro-duplicate-params-names-err.s
Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=299815&r1=299814&r2=299815&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sat Apr  8 15:29:03 2017
@@ -3874,6 +3874,12 @@ bool AsmParser::parseDirectiveMacro(SMLo
     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 multiple parameters"
+                        " named '" + Parameter.Name + "'");
+
     if (Lexer.is(AsmToken::Colon)) {
       Lex();  // consume ':'
 

Added: llvm/trunk/test/MC/AsmParser/macro-duplicate-params-names-err.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/macro-duplicate-params-names-err.s?rev=299815&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/macro-duplicate-params-names-err.s (added)
+++ llvm/trunk/test/MC/AsmParser/macro-duplicate-params-names-err.s Sat Apr  8 15:29:03 2017
@@ -0,0 +1,7 @@
+// RUN: not llvm-mc %s 2> %t
+// RUN: FileCheck < %t %s
+
+.macro M a a
+.endm
+
+// CHECK: macro 'M' has multiple parameters named 'a'




More information about the llvm-commits mailing list