[llvm] 835c2aa - [MC] Reorganize and improve macro tests
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 12 22:54:39 PDT 2020
Author: Fangrui Song
Date: 2020-04-12T22:54:01-07:00
New Revision: 835c2aa7a68bb1fc559233e007f8e57b263eac99
URL: https://github.com/llvm/llvm-project/commit/835c2aa7a68bb1fc559233e007f8e57b263eac99
DIFF: https://github.com/llvm/llvm-project/commit/835c2aa7a68bb1fc559233e007f8e57b263eac99.diff
LOG: [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.
Added:
llvm/test/MC/AsmParser/altmacro-err.s
llvm/test/MC/AsmParser/altmacro-expr-err.s
llvm/test/MC/AsmParser/macro-at-pseudo-variable-err.s
llvm/test/MC/AsmParser/macro-at-pseudo-variable.s
llvm/test/MC/AsmParser/macro-same-context.ll
llvm/test/MC/AsmParser/macro-vararg-err.s
llvm/test/MC/AsmParser/macro-vararg.s
llvm/test/MC/AsmParser/unmatched-if-macro.s
llvm/test/MC/AsmParser/unmatched-if.s
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/AsmParser/macro-arg-err.s
Removed:
llvm/test/MC/AsmParser/at-pseudo-variable-bad.s
llvm/test/MC/AsmParser/at-pseudo-variable.s
llvm/test/MC/AsmParser/bad-macro.s
llvm/test/MC/AsmParser/inline_macro_duplication.ll
llvm/test/MC/AsmParser/invalid-input-assertion.s
llvm/test/MC/AsmParser/negativ_altmacro_expression.s
llvm/test/MC/AsmParser/negative_altmacro_string.s
llvm/test/MC/AsmParser/vararg.s
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index c5c44a7861f0..1a38806f1e97 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 313607b7782c..000000000000
--- 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 2557f6e4aa6f..000000000000
--- 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 4aa27ddc71b7..f4dd86feb196 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 f2c2932b8057..fac30e44193f 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 000000000000..8561c69a1fa9
--- /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 000000000000..79b6801e2b72
--- /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 000000000000..8ccbd5c043b4
--- /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: <instantiation>: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 000000000000..b2451666eb78
--- /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 dae81dfb78ce..000000000000
--- 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
More information about the llvm-commits
mailing list