From b28be420c04f252b61a265e2d3c687c162cb7720 Mon Sep 17 00:00:00 2001 From: Coby Tayree Date: Sat, 8 Apr 2017 20:29:03 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299815 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 6 ++++++ test/MC/AsmParser/macro-duplicate-params-names-err.s | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 test/MC/AsmParser/macro-duplicate-params-names-err.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 9d5eaf31408..e65ce9f0b93 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -3874,6 +3874,12 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) { 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 ':' diff --git a/test/MC/AsmParser/macro-duplicate-params-names-err.s b/test/MC/AsmParser/macro-duplicate-params-names-err.s new file mode 100644 index 00000000000..618cce02abd --- /dev/null +++ b/test/MC/AsmParser/macro-duplicate-params-names-err.s @@ -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'