From 93d7286ccd63b3eb8c89f98f9342950268026a9d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 12 Apr 2020 22:02:55 -0700 Subject: [PATCH] [MC] Reorganize and improve macro tests * Reorganize tests and add coverage * Improve diagnostic testing * Make assert() tests more relevant * Rename tests to macro-* or altmacro-* This is not NFC because a (previously untested) diagnostic message is changed. --- lib/MC/MCParser/AsmParser.cpp | 6 +-- ...ative_altmacro_string.s => altmacro-err.s} | 0 ...macro_expression.s => altmacro-expr-err.s} | 0 test/MC/AsmParser/bad-macro.s | 9 ---- test/MC/AsmParser/invalid-input-assertion.s | 9 ---- test/MC/AsmParser/macro-arg-err.s | 10 ++++ ...e-bad.s => macro-at-pseudo-variable-err.s} | 0 ...-variable.s => macro-at-pseudo-variable.s} | 0 ...o_duplication.ll => macro-same-context.ll} | 2 + test/MC/AsmParser/macro-vararg-err.s | 17 +++++++ test/MC/AsmParser/macro-vararg.s | 37 ++++++++++++++ test/MC/AsmParser/unmatched-if-macro.s | 12 +++++ test/MC/AsmParser/unmatched-if.s | 5 ++ test/MC/AsmParser/vararg.s | 51 ------------------- 14 files changed, 86 insertions(+), 72 deletions(-) rename test/MC/AsmParser/{negative_altmacro_string.s => altmacro-err.s} (100%) rename test/MC/AsmParser/{negativ_altmacro_expression.s => altmacro-expr-err.s} (100%) delete mode 100644 test/MC/AsmParser/bad-macro.s delete mode 100644 test/MC/AsmParser/invalid-input-assertion.s rename test/MC/AsmParser/{at-pseudo-variable-bad.s => macro-at-pseudo-variable-err.s} (100%) rename test/MC/AsmParser/{at-pseudo-variable.s => macro-at-pseudo-variable.s} (100%) rename test/MC/AsmParser/{inline_macro_duplication.ll => macro-same-context.ll} (70%) create mode 100644 test/MC/AsmParser/macro-vararg-err.s create mode 100644 test/MC/AsmParser/macro-vararg.s create mode 100644 test/MC/AsmParser/unmatched-if-macro.s create mode 100644 test/MC/AsmParser/unmatched-if.s delete mode 100644 test/MC/AsmParser/vararg.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index c5c44a7861f..1a38806f1e9 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -4382,9 +4382,9 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) { while (getLexer().isNot(AsmToken::EndOfStatement)) { if (!Parameters.empty() && Parameters.back().Vararg) - return Error(Lexer.getLoc(), - "Vararg parameter '" + Parameters.back().Name + - "' should be last one in the list of parameters."); + return Error(Lexer.getLoc(), "vararg parameter '" + + Parameters.back().Name + + "' should be the last parameter"); MCAsmMacroParameter Parameter; if (parseIdentifier(Parameter.Name)) diff --git a/test/MC/AsmParser/negative_altmacro_string.s b/test/MC/AsmParser/altmacro-err.s similarity index 100% rename from test/MC/AsmParser/negative_altmacro_string.s rename to test/MC/AsmParser/altmacro-err.s diff --git a/test/MC/AsmParser/negativ_altmacro_expression.s b/test/MC/AsmParser/altmacro-expr-err.s similarity index 100% rename from test/MC/AsmParser/negativ_altmacro_expression.s rename to test/MC/AsmParser/altmacro-expr-err.s diff --git a/test/MC/AsmParser/bad-macro.s b/test/MC/AsmParser/bad-macro.s deleted file mode 100644 index 313607b7782..00000000000 --- a/test/MC/AsmParser/bad-macro.s +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s 2>&1 | FileCheck %s - -.macro 23 - -// CHECK: expected identifier in '.macro' directive - -.macro abc 33 - -// CHECK: expected identifier in '.macro' directive diff --git a/test/MC/AsmParser/invalid-input-assertion.s b/test/MC/AsmParser/invalid-input-assertion.s deleted file mode 100644 index 2557f6e4aa6..00000000000 --- a/test/MC/AsmParser/invalid-input-assertion.s +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: not llvm-mc -triple i686-linux -o /dev/null %s - - .macro macro parameter=0 - .if \parameter - .else - .endm - - macro 1 - diff --git a/test/MC/AsmParser/macro-arg-err.s b/test/MC/AsmParser/macro-arg-err.s index 4aa27ddc71b..f4dd86feb19 100644 --- a/test/MC/AsmParser/macro-arg-err.s +++ b/test/MC/AsmParser/macro-arg-err.s @@ -44,3 +44,13 @@ double second = 1, 2 # CHECK-NEXT:double third = 0 # CHECK-NEXT: ^ double third = 0 + +# CHECK-NEXT:{{.*}}.s:[[#@LINE+3]]:8: error: expected identifier in '.macro' directive +# CHECK-NEXT:.macro 23 +# CHECK-NEXT: ^ +.macro 23 + +# CHECK-NEXT:{{.*}}.s:[[#@LINE+3]]:10: error: expected identifier in '.macro' directive +# CHECK-NEXT:.macro a 23 +# CHECK-NEXT: ^ +.macro a 23 diff --git a/test/MC/AsmParser/at-pseudo-variable-bad.s b/test/MC/AsmParser/macro-at-pseudo-variable-err.s similarity index 100% rename from test/MC/AsmParser/at-pseudo-variable-bad.s rename to test/MC/AsmParser/macro-at-pseudo-variable-err.s diff --git a/test/MC/AsmParser/at-pseudo-variable.s b/test/MC/AsmParser/macro-at-pseudo-variable.s similarity index 100% rename from test/MC/AsmParser/at-pseudo-variable.s rename to test/MC/AsmParser/macro-at-pseudo-variable.s diff --git a/test/MC/AsmParser/inline_macro_duplication.ll b/test/MC/AsmParser/macro-same-context.ll similarity index 70% rename from test/MC/AsmParser/inline_macro_duplication.ll rename to test/MC/AsmParser/macro-same-context.ll index f2c2932b805..fac30e44193 100644 --- a/test/MC/AsmParser/inline_macro_duplication.ll +++ b/test/MC/AsmParser/macro-same-context.ll @@ -1,3 +1,5 @@ +;; Test that macros in inline assembly blocks share the same context, +;; thus a definition is available to the whole file. PR36110 ; RUN: not llc < %s 2>&1 | FileCheck %s ; REQUIRES: default_triple diff --git a/test/MC/AsmParser/macro-vararg-err.s b/test/MC/AsmParser/macro-vararg-err.s new file mode 100644 index 00000000000..8561c69a1fa --- /dev/null +++ b/test/MC/AsmParser/macro-vararg-err.s @@ -0,0 +1,17 @@ +# RUN: not llvm-mc -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --match-full-lines --strict-whitespace + +# CHECK:{{.*}}.s:[[#@LINE+3]]:21: error: vararg parameter 'a' should be the last parameter +# CHECK-NEXT:.macro two a:vararg b:vararg +# CHECK-NEXT: ^ +.macro two a:vararg b:vararg + +# CHECK:{{.*}}.s:[[#@LINE+3]]:17: error: expected identifier in '.macro' directive +# CHECK-NEXT:.macro one a:req:vararg +# CHECK-NEXT: ^ +.macro one a:req:vararg + +# CHECK-NEXT:{{.*}}.s:[[#@LINE+3]]:32: warning: pointless default value for required parameter 'a' in macro 'pointless_default' +# CHECK-NEXT:.macro pointless_default a:req=default +# CHECK-NEXT: ^ +.macro pointless_default a:req=default +.endm diff --git a/test/MC/AsmParser/macro-vararg.s b/test/MC/AsmParser/macro-vararg.s new file mode 100644 index 00000000000..79b6801e2b7 --- /dev/null +++ b/test/MC/AsmParser/macro-vararg.s @@ -0,0 +1,37 @@ +# RUN: llvm-mc -triple=x86_64 %s | FileCheck %s +.macro one a:vararg +.ascii "|\a" +.endm + +# CHECK: .byte 124 +one +# CHECK: .ascii "|1" +one 1 +## Difference: GNU as squeezes repeated spaces. +# CHECK: .ascii "|1 2" +one 1 2 +## Difference: GNU as non-x86 drops the space before '(' (gas PR/25750) +# CHECK: .ascii "|1 (2 3" +one 1 (2 3 +# CHECK: .ascii "|1 2 3)" +one 1 2 3) + +.macro two a, b:vararg +.ascii "|\a|\b" +.endm + +# CHECK: .ascii "||" +two +# CHECK: .ascii "|1|" +two 1 +## Difference: GNU as squeezes repeated spaces. +# CHECK: .ascii "|1|2 3" +two 1 2 3 + +## Parameters can be separated by spaces +.macro two1 a b:vararg +.ascii "|\a|\b" +.endm + +# CHECK: .ascii "|1|2" +two1 1 2 diff --git a/test/MC/AsmParser/unmatched-if-macro.s b/test/MC/AsmParser/unmatched-if-macro.s new file mode 100644 index 00000000000..8ccbd5c043b --- /dev/null +++ b/test/MC/AsmParser/unmatched-if-macro.s @@ -0,0 +1,12 @@ +# RUN: not llvm-mc -triple x86_64 %s -o /dev/null 2>&1 | FileCheck %s + +## This also tests that we don't assert due to an active macro instantiation. +# CHECK: :4:1: error: unmatched .ifs or .elses + + .macro macro parameter=0 + .if \parameter + .else + .endm + + macro 1 + diff --git a/test/MC/AsmParser/unmatched-if.s b/test/MC/AsmParser/unmatched-if.s new file mode 100644 index 00000000000..b2451666eb7 --- /dev/null +++ b/test/MC/AsmParser/unmatched-if.s @@ -0,0 +1,5 @@ +# RUN: not llvm-mc -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s + +# CHECK: {{.*}}.s:6:1: error: unmatched .ifs or .elses +.if 1 +.else diff --git a/test/MC/AsmParser/vararg.s b/test/MC/AsmParser/vararg.s deleted file mode 100644 index dae81dfb78c..00000000000 --- a/test/MC/AsmParser/vararg.s +++ /dev/null @@ -1,51 +0,0 @@ -// RUN: llvm-mc -triple x86_64-linux-gnu %s | FileCheck %s -.macro ifcc arg:vararg -.if cc - \arg -.endif -.endm - -.macro ifcc2 arg0 arg1:vararg -.if cc - movl \arg0, \arg1 -.endif -.endm - -.macro ifcc3 arg0, arg1:vararg -.if cc - movl \arg0, \arg1 -.endif -.endm - -.macro ifcc4 arg0, arg1:vararg -.if cc - movl \arg1, \arg0 -.endif -.endm - -.text - -// CHECK: movl %esp, %ebp -// CHECK: subl $0, %esp -// CHECK: movl %eax, %ebx -// CHECK: movl %ecx, %ebx -// CHECK: movl %ecx, %eax -// CHECK: movl %eax, %ecx -// CHECK: movl %ecx, %eax -// CHECK: movl %eax, %ecx -.set cc,1 - ifcc movl %esp, %ebp - subl $0, %esp - - ifcc2 %eax %ebx - ifcc2 %ecx, %ebx - ifcc3 %ecx %eax - ifcc3 %eax, %ecx - ifcc4 %eax %ecx ## test - ifcc4 %ecx, %eax ## test - -// CHECK-NOT: movl -// CHECK: subl $1, %esp -.set cc,0 - ifcc movl %esp, %ebp - subl $1, %esp