freebsd-dev/contrib/llvm/patches/patch-r274286-llvm-r201784-asm-dollar.diff

368 lines
8.5 KiB
Diff
Raw Normal View History

Pull in r200383 from upstream llvm trunk (by David Majnemer):
MC: Reorganize macro MC test along dialect lines
This commit seeks to do two things:
- Run the surfeit of tests under the Darwin dialect. This ends up
affecting tests which assumed that spaces could deliminate arguments.
- The GAS dialect tests should limit their surface area to things that
could plausibly work under GAS. For example, Darwin style arguments
have no business being in such a test.
Pull in r201784 from upstream llvm trunk (by Benjamin Kramer):
AsmParser: Disable Darwin-style macro argument expansion on non-darwin targets.
There is code in the wild that relies on $0 not being expanded.
This fixes some cases of using $ signs in literals being incorrectly
assembled.
Reported by: Richard Henderson
Upstream PR: http://llvm.org/PR21500
Introduced here: http://svnweb.freebsd.org/changeset/base/274286
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -1695,7 +1695,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
const MCAsmMacroParameters &Parameters,
const MCAsmMacroArguments &A, const SMLoc &L) {
unsigned NParameters = Parameters.size();
- if (NParameters != 0 && NParameters != A.size())
+ if ((!IsDarwin || NParameters != 0) && NParameters != A.size())
return Error(L, "Wrong number of arguments");
// A macro without parameters is handled differently on Darwin:
@@ -1705,7 +1705,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
std::size_t End = Body.size(), Pos = 0;
for (; Pos != End; ++Pos) {
// Check for a substitution or escape.
- if (!NParameters) {
+ if (IsDarwin && !NParameters) {
// This macro has no parameters, look for $0, $1, etc.
if (Body[Pos] != '$' || Pos + 1 == End)
continue;
@@ -1728,7 +1728,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
if (Pos == End)
break;
- if (!NParameters) {
+ if (IsDarwin && !NParameters) {
switch (Body[Pos + 1]) {
// $$ => $
case '$':
Index: test/MC/AsmParser/exprs.s
===================================================================
--- test/MC/AsmParser/exprs.s
+++ test/MC/AsmParser/exprs.s
@@ -1,4 +1,4 @@
-// RUN: llvm-mc -triple i386-unknown-unknown %s > %t
+// RUN: llvm-mc -triple i386-apple-darwin %s
.macro check_expr
.if ($0) != ($1)
Index: test/MC/AsmParser/macros.s
===================================================================
--- test/MC/AsmParser/macros.s
+++ test/MC/AsmParser/macros.s
@@ -1,93 +0,0 @@
-// RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t.err | FileCheck %s
-// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
-
-.macro .test0
-.macrobody0
-.endmacro
-.macro .test1
-.test0
-.endmacro
-
-.test1
-// CHECK-ERRORS: <instantiation>:1:1: error: unknown directive
-// CHECK-ERRORS-NEXT: macrobody0
-// CHECK-ERRORS-NEXT: ^
-// CHECK-ERRORS: <instantiation>:1:1: note: while in macro instantiation
-// CHECK-ERRORS-NEXT: .test0
-// CHECK-ERRORS-NEXT: ^
-// CHECK-ERRORS: 11:1: note: while in macro instantiation
-// CHECK-ERRORS-NEXT: .test1
-// CHECK-ERRORS-NEXT: ^
-
-.macro test2
-.byte $0
-.endmacro
-test2 10
-
-.macro test3
-.globl "$0 $1 $2 $$3 $n"
-.endmacro
-
-// CHECK: .globl "1 (23) $3 2"
-test3 1, (2 3)
-
-// CHECK: .globl "1 2 $3 2"
-test3 1 2
-
-.macro test4
-.globl "$0 -- $1"
-.endmacro
-
-// CHECK: .globl "(ab)(,)) -- (cd)"
-test4 (a b)(,)),(cd)
-
-// CHECK: .globl "(ab)(,)) -- (cd)"
-test4 (a b)(,)),(cd)
-
-.macro test5 _a
-.globl "\_a"
-.endm
-
-// CHECK: .globl zed1
-test5 zed1
-
-.macro test6 $a
-.globl "\$a"
-.endm
-
-// CHECK: .globl zed2
-test6 zed2
-
-.macro test7 .a
-.globl "\.a"
-.endm
-
-// CHECK: .globl zed3
-test7 zed3
-
-.macro test8 _a, _b, _c
-.globl "\_a,\_b,\_c"
-.endmacro
-
-.macro test9 _a _b _c
-.globl "\_a \_b \_c"
-.endmacro
-
-// CHECK: .globl "a,b,c"
-test8 a, b, c
-// CHECK: .globl "%1,%2,%3"
-test8 %1 %2 %3 #a comment
-// CHECK: .globl "x-y,z,1"
-test8 x - y z 1
-// CHECK: .globl "1 2 3"
-test9 1, 2,3
-
-test8 1,2 3
-// CHECK-ERRORS: error: macro argument '_c' is missing
-// CHECK-ERRORS-NEXT: test8 1,2 3
-// CHECK-ERRORS-NEXT: ^
-
-test8 1 2, 3
-// CHECK-ERRORS: error: expected ' ' for macro argument separator
-// CHECK-ERRORS-NEXT:test8 1 2, 3
-// CHECK-ERRORS-NEXT: ^
Index: test/MC/AsmParser/macros-darwin.s
===================================================================
--- test/MC/AsmParser/macros-darwin.s
+++ test/MC/AsmParser/macros-darwin.s
@@ -1,9 +1,97 @@
-// RUN: llvm-mc -triple i386-apple-darwin10 %s | FileCheck %s
+// RUN: not llvm-mc -triple i386-apple-darwin10 %s 2> %t.err | FileCheck %s
+// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
-.macro test1
+.macro .test0
+.macrobody0
+.endmacro
+.macro .test1
+.test0
+.endmacro
+
+.test1
+// CHECK-ERRORS: <instantiation>:1:1: error: unknown directive
+// CHECK-ERRORS-NEXT: macrobody0
+// CHECK-ERRORS-NEXT: ^
+// CHECK-ERRORS: <instantiation>:1:1: note: while in macro instantiation
+// CHECK-ERRORS-NEXT: .test0
+// CHECK-ERRORS-NEXT: ^
+// CHECK-ERRORS: 11:1: note: while in macro instantiation
+// CHECK-ERRORS-NEXT: .test1
+// CHECK-ERRORS-NEXT: ^
+
+.macro test2
+.byte $0
+.endmacro
+// CHECK: .byte 10
+test2 10
+
+.macro test3
.globl "$0 $1 $2 $$3 $n"
.endmacro
// CHECK: .globl "1 23 $3 2"
-test1 1, 2 3
+test3 1, 2 3
+// CHECK: .globl "1 (23) $3 2"
+test3 1, (2 3)
+
+// CHECK: .globl "12 $3 1"
+test3 1 2
+
+.macro test4
+.globl "$0 -- $1"
+.endmacro
+
+// CHECK: .globl "(ab)(,)) -- (cd)"
+test4 (a b)(,)),(cd)
+
+// CHECK: .globl "(ab)(,)) -- (cd)"
+test4 (a b)(,)),(cd)
+
+.macro test5 _a
+.globl "\_a"
+.endm
+
+// CHECK: .globl zed1
+test5 zed1
+
+.macro test6 $a
+.globl "\$a"
+.endm
+
+// CHECK: .globl zed2
+test6 zed2
+
+.macro test7 .a
+.globl "\.a"
+.endm
+
+// CHECK: .globl zed3
+test7 zed3
+
+.macro test8 _a, _b, _c
+.globl "\_a,\_b,\_c"
+.endmacro
+
+.macro test9 _a _b _c
+.globl "\_a \_b \_c"
+.endmacro
+
+// CHECK: .globl "a,b,c"
+test8 a, b, c
+// CHECK: .globl "%1,%2,%3"
+test8 %1, %2, %3 #a comment
+// CHECK: .globl "x-y,z,1"
+test8 x - y, z, 1
+// CHECK: .globl "1 2 3"
+test9 1, 2,3
+
+test8 1,2 3
+// CHECK-ERRORS: error: macro argument '_c' is missing
+// CHECK-ERRORS-NEXT: test8 1,2 3
+// CHECK-ERRORS-NEXT: ^
+
+test8 1 2, 3
+// CHECK-ERRORS: error: macro argument '_c' is missing
+// CHECK-ERRORS-NEXT:test8 1 2, 3
+// CHECK-ERRORS-NEXT: ^
Index: test/MC/AsmParser/macros-gas.s
===================================================================
--- test/MC/AsmParser/macros-gas.s
+++ test/MC/AsmParser/macros-gas.s
@@ -0,0 +1,93 @@
+// RUN: not llvm-mc -triple i386-linux-gnu %s 2> %t.err | FileCheck %s
+// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
+
+.macro .test0
+.macrobody0
+.endm
+.macro .test1
+.test0
+.endm
+
+.test1
+// CHECK-ERRORS: <instantiation>:1:1: error: unknown directive
+// CHECK-ERRORS-NEXT: macrobody0
+// CHECK-ERRORS-NEXT: ^
+// CHECK-ERRORS: <instantiation>:1:1: note: while in macro instantiation
+// CHECK-ERRORS-NEXT: .test0
+// CHECK-ERRORS-NEXT: ^
+// CHECK-ERRORS: 11:1: note: while in macro instantiation
+// CHECK-ERRORS-NEXT: .test1
+// CHECK-ERRORS-NEXT: ^
+
+.macro test2 _a
+.byte \_a
+.endm
+// CHECK: .byte 10
+test2 10
+
+.macro test3 _a _b _c
+.ascii "\_a \_b \_c \\_c"
+.endm
+
+// CHECK: .ascii "1 2 3 \003"
+test3 1, 2, 3
+
+// FIXME: test3 1, 2 3 should be treated like test 1, 2, 3
+
+// FIXME: remove the n argument from the remaining test3 examples
+// CHECK: .ascii "1 (23) n \n"
+test3 1, (2 3), n
+
+// CHECK: .ascii "1 (23) n \n"
+test3 1 (2 3) n
+
+// CHECK: .ascii "1 2 n \n"
+test3 1 2 n
+
+.macro test5 _a
+.globl \_a
+.endm
+
+// CHECK: .globl zed1
+test5 zed1
+
+.macro test6 $a
+.globl \$a
+.endm
+
+// CHECK: .globl zed2
+test6 zed2
+
+.macro test7 .a
+.globl \.a
+.endm
+
+// CHECK: .globl zed3
+test7 zed3
+
+.macro test8 _a, _b, _c
+.ascii "\_a,\_b,\_c"
+.endm
+
+.macro test9 _a _b _c
+.ascii "\_a \_b \_c"
+.endm
+
+// CHECK: .ascii "a,b,c"
+test8 a, b, c
+// CHECK: .ascii "%1,%2,%3"
+test8 %1 %2 %3 #a comment
+// CHECK: .ascii "x-y,z,1"
+test8 x - y z 1
+// CHECK: .ascii "1 2 3"
+test9 1, 2,3
+
+test8 1,2 3
+// CHECK-ERRORS: error: macro argument '_c' is missing
+// CHECK-ERRORS-NEXT: test8 1,2 3
+// CHECK-ERRORS-NEXT: ^
+
+test8 1 2, 3
+// CHECK-ERRORS: error: expected ' ' for macro argument separator
+// CHECK-ERRORS-NEXT:test8 1 2, 3
+// CHECK-ERRORS-NEXT: ^