From 835c2aa7a68bb1fc559233e007f8e57b263eac99 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. --- llvm/lib/MC/MCParser/AsmParser.cpp | 6 +-- .../{negative_altmacro_string.s => altmacro-err.s} | 0 ...v_altmacro_expression.s => altmacro-expr-err.s} | 0 llvm/test/MC/AsmParser/bad-macro.s | 9 ---- llvm/test/MC/AsmParser/invalid-input-assertion.s | 9 ---- llvm/test/MC/AsmParser/macro-arg-err.s | 10 +++++ ...riable-bad.s => macro-at-pseudo-variable-err.s} | 0 ...seudo-variable.s => macro-at-pseudo-variable.s} | 0 ..._macro_duplication.ll => macro-same-context.ll} | 2 + llvm/test/MC/AsmParser/macro-vararg-err.s | 17 ++++++++ llvm/test/MC/AsmParser/macro-vararg.s | 37 ++++++++++++++++ llvm/test/MC/AsmParser/unmatched-if-macro.s | 12 +++++ llvm/test/MC/AsmParser/unmatched-if.s | 5 +++ llvm/test/MC/AsmParser/vararg.s | 51 ---------------------- 14 files changed, 86 insertions(+), 72 deletions(-) rename llvm/test/MC/AsmParser/{negative_altmacro_string.s => altmacro-err.s} (100%) rename llvm/test/MC/AsmParser/{negativ_altmacro_expression.s => altmacro-expr-err.s} (100%) delete mode 100644 llvm/test/MC/AsmParser/bad-macro.s delete mode 100644 llvm/test/MC/AsmParser/invalid-input-assertion.s rename llvm/test/MC/AsmParser/{at-pseudo-variable-bad.s => macro-at-pseudo-variable-err.s} (100%) rename llvm/test/MC/AsmParser/{at-pseudo-variable.s => macro-at-pseudo-variable.s} (100%) rename llvm/test/MC/AsmParser/{inline_macro_duplication.ll => macro-same-context.ll} (70%) create mode 100644 llvm/test/MC/AsmParser/macro-vararg-err.s create mode 100644 llvm/test/MC/AsmParser/macro-vararg.s create mode 100644 llvm/test/MC/AsmParser/unmatched-if-macro.s create mode 100644 llvm/test/MC/AsmParser/unmatched-if.s delete mode 100644 llvm/test/MC/AsmParser/vararg.s diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index c5c44a7..1a38806 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/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/llvm/test/MC/AsmParser/negative_altmacro_string.s b/llvm/test/MC/AsmParser/altmacro-err.s similarity index 100% rename from llvm/test/MC/AsmParser/negative_altmacro_string.s rename to llvm/test/MC/AsmParser/altmacro-err.s diff --git a/llvm/test/MC/AsmParser/negativ_altmacro_expression.s b/llvm/test/MC/AsmParser/altmacro-expr-err.s similarity index 100% rename from llvm/test/MC/AsmParser/negativ_altmacro_expression.s rename to llvm/test/MC/AsmParser/altmacro-expr-err.s diff --git a/llvm/test/MC/AsmParser/bad-macro.s b/llvm/test/MC/AsmParser/bad-macro.s deleted file mode 100644 index 313607b..0000000 --- a/llvm/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/llvm/test/MC/AsmParser/invalid-input-assertion.s b/llvm/test/MC/AsmParser/invalid-input-assertion.s deleted file mode 100644 index 2557f6e..0000000 --- a/llvm/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/llvm/test/MC/AsmParser/macro-arg-err.s b/llvm/test/MC/AsmParser/macro-arg-err.s index 4aa27dd..f4dd86f 100644 --- a/llvm/test/MC/AsmParser/macro-arg-err.s +++ b/llvm/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/llvm/test/MC/AsmParser/at-pseudo-variable-bad.s b/llvm/test/MC/AsmParser/macro-at-pseudo-variable-err.s similarity index 100% rename from llvm/test/MC/AsmParser/at-pseudo-variable-bad.s rename to llvm/test/MC/AsmParser/macro-at-pseudo-variable-err.s diff --git a/llvm/test/MC/AsmParser/at-pseudo-variable.s b/llvm/test/MC/AsmParser/macro-at-pseudo-variable.s similarity index 100% rename from llvm/test/MC/AsmParser/at-pseudo-variable.s rename to llvm/test/MC/AsmParser/macro-at-pseudo-variable.s diff --git a/llvm/test/MC/AsmParser/inline_macro_duplication.ll b/llvm/test/MC/AsmParser/macro-same-context.ll similarity index 70% rename from llvm/test/MC/AsmParser/inline_macro_duplication.ll rename to llvm/test/MC/AsmParser/macro-same-context.ll index f2c2932..fac30e4 100644 --- a/llvm/test/MC/AsmParser/inline_macro_duplication.ll +++ b/llvm/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/llvm/test/MC/AsmParser/macro-vararg-err.s b/llvm/test/MC/AsmParser/macro-vararg-err.s new file mode 100644 index 0000000..8561c69 --- /dev/null +++ b/llvm/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/llvm/test/MC/AsmParser/macro-vararg.s b/llvm/test/MC/AsmParser/macro-vararg.s new file mode 100644 index 0000000..79b6801 --- /dev/null +++ b/llvm/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/llvm/test/MC/AsmParser/unmatched-if-macro.s b/llvm/test/MC/AsmParser/unmatched-if-macro.s new file mode 100644 index 0000000..8ccbd5c0 --- /dev/null +++ b/llvm/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/llvm/test/MC/AsmParser/unmatched-if.s b/llvm/test/MC/AsmParser/unmatched-if.s new file mode 100644 index 0000000..b245166 --- /dev/null +++ b/llvm/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/llvm/test/MC/AsmParser/vararg.s b/llvm/test/MC/AsmParser/vararg.s deleted file mode 100644 index dae81df..0000000 --- a/llvm/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 -- 2.7.4