patch-r274286-llvm-r201784-asm-dollar.diff revision 283015
1Pull in r200383 from upstream llvm trunk (by David Majnemer):
2
3  MC: Reorganize macro MC test along dialect lines
4
5  This commit seeks to do two things:
6  - Run the surfeit of tests under the Darwin dialect.  This ends up
7    affecting tests which assumed that spaces could deliminate arguments.
8  - The GAS dialect tests should limit their surface area to things that
9    could plausibly work under GAS. For example, Darwin style arguments
10    have no business being in such a test.
11
12Pull in r201784 from upstream llvm trunk (by Benjamin Kramer):
13
14  AsmParser: Disable Darwin-style macro argument expansion on non-darwin targets.
15
16  There is code in the wild that relies on $0 not being expanded.
17
18This fixes some cases of using $ signs in literals being incorrectly
19assembled.
20
21Reported by:	Richard Henderson
22Upstream PR:	http://llvm.org/PR21500
23
24Introduced here: http://svnweb.freebsd.org/changeset/base/274286
25
26Index: lib/MC/MCParser/AsmParser.cpp
27===================================================================
28--- lib/MC/MCParser/AsmParser.cpp
29+++ lib/MC/MCParser/AsmParser.cpp
30@@ -1695,7 +1695,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
31                             const MCAsmMacroParameters &Parameters,
32                             const MCAsmMacroArguments &A, const SMLoc &L) {
33   unsigned NParameters = Parameters.size();
34-  if (NParameters != 0 && NParameters != A.size())
35+  if ((!IsDarwin || NParameters != 0) && NParameters != A.size())
36     return Error(L, "Wrong number of arguments");
37 
38   // A macro without parameters is handled differently on Darwin:
39@@ -1705,7 +1705,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
40     std::size_t End = Body.size(), Pos = 0;
41     for (; Pos != End; ++Pos) {
42       // Check for a substitution or escape.
43-      if (!NParameters) {
44+      if (IsDarwin && !NParameters) {
45         // This macro has no parameters, look for $0, $1, etc.
46         if (Body[Pos] != '$' || Pos + 1 == End)
47           continue;
48@@ -1728,7 +1728,7 @@ bool AsmParser::expandMacro(raw_svector_ostream &O
49     if (Pos == End)
50       break;
51 
52-    if (!NParameters) {
53+    if (IsDarwin && !NParameters) {
54       switch (Body[Pos + 1]) {
55       // $$ => $
56       case '$':
57Index: test/MC/AsmParser/exprs.s
58===================================================================
59--- test/MC/AsmParser/exprs.s
60+++ test/MC/AsmParser/exprs.s
61@@ -1,4 +1,4 @@
62-// RUN: llvm-mc -triple i386-unknown-unknown %s > %t
63+// RUN: llvm-mc -triple i386-apple-darwin %s
64 
65 .macro check_expr
66   .if ($0) != ($1)
67Index: test/MC/AsmParser/macros.s (deleted)
68===================================================================
69Index: test/MC/AsmParser/macros-darwin.s
70===================================================================
71--- test/MC/AsmParser/macros-darwin.s
72+++ test/MC/AsmParser/macros-darwin.s
73@@ -1,9 +1,97 @@
74-// RUN: llvm-mc -triple i386-apple-darwin10 %s | FileCheck %s
75+// RUN: not llvm-mc -triple i386-apple-darwin10 %s 2> %t.err | FileCheck %s
76+// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
77 
78-.macro test1
79+.macro .test0
80+.macrobody0
81+.endmacro
82+.macro .test1
83+.test0
84+.endmacro
85+
86+.test1
87+// CHECK-ERRORS: <instantiation>:1:1: error: unknown directive
88+// CHECK-ERRORS-NEXT: macrobody0
89+// CHECK-ERRORS-NEXT: ^
90+// CHECK-ERRORS: <instantiation>:1:1: note: while in macro instantiation
91+// CHECK-ERRORS-NEXT: .test0
92+// CHECK-ERRORS-NEXT: ^
93+// CHECK-ERRORS: 11:1: note: while in macro instantiation
94+// CHECK-ERRORS-NEXT: .test1
95+// CHECK-ERRORS-NEXT: ^
96+
97+.macro test2
98+.byte $0
99+.endmacro
100+// CHECK: .byte 10
101+test2 10
102+
103+.macro test3
104 .globl "$0 $1 $2 $$3 $n"
105 .endmacro
106 
107 // CHECK: .globl "1 23  $3 2"
108-test1 1, 2 3
109+test3 1, 2 3
110 
111+// CHECK: .globl	"1 (23)  $3 2"
112+test3 1, (2 3)
113+
114+// CHECK: .globl "12  $3 1"
115+test3 1 2
116+
117+.macro test4
118+.globl "$0 -- $1"
119+.endmacro
120+
121+// CHECK: .globl  "(ab)(,)) -- (cd)"
122+test4 (a b)(,)),(cd)
123+
124+// CHECK: .globl  "(ab)(,)) -- (cd)"
125+test4 (a b)(,)),(cd)
126+
127+.macro test5 _a
128+.globl "\_a"
129+.endm
130+
131+// CHECK: .globl zed1
132+test5 zed1
133+
134+.macro test6 $a
135+.globl "\$a"
136+.endm
137+
138+// CHECK: .globl zed2
139+test6 zed2
140+
141+.macro test7 .a
142+.globl "\.a"
143+.endm
144+
145+// CHECK: .globl zed3
146+test7 zed3
147+
148+.macro test8 _a, _b, _c
149+.globl "\_a,\_b,\_c"
150+.endmacro
151+
152+.macro test9 _a _b _c
153+.globl "\_a \_b \_c"
154+.endmacro
155+
156+// CHECK: .globl  "a,b,c"
157+test8 a, b, c
158+// CHECK: .globl  "%1,%2,%3"
159+test8 %1, %2, %3 #a comment
160+// CHECK: .globl "x-y,z,1"
161+test8 x - y, z, 1
162+// CHECK: .globl  "1 2 3"
163+test9 1, 2,3
164+
165+test8 1,2 3
166+// CHECK-ERRORS: error: macro argument '_c' is missing
167+// CHECK-ERRORS-NEXT: test8 1,2 3
168+// CHECK-ERRORS-NEXT:           ^
169+
170+test8 1 2, 3
171+// CHECK-ERRORS: error: macro argument '_c' is missing
172+// CHECK-ERRORS-NEXT:test8 1 2, 3
173+// CHECK-ERRORS-NEXT:           ^
174Index: test/MC/AsmParser/macros-gas.s
175===================================================================
176--- test/MC/AsmParser/macros-gas.s
177+++ test/MC/AsmParser/macros-gas.s
178@@ -0,0 +1,93 @@
179+// RUN: not llvm-mc -triple i386-linux-gnu %s 2> %t.err | FileCheck %s
180+// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err
181+
182+.macro .test0
183+.macrobody0
184+.endm
185+.macro .test1
186+.test0
187+.endm
188+
189+.test1
190+// CHECK-ERRORS: <instantiation>:1:1: error: unknown directive
191+// CHECK-ERRORS-NEXT: macrobody0
192+// CHECK-ERRORS-NEXT: ^
193+// CHECK-ERRORS: <instantiation>:1:1: note: while in macro instantiation
194+// CHECK-ERRORS-NEXT: .test0
195+// CHECK-ERRORS-NEXT: ^
196+// CHECK-ERRORS: 11:1: note: while in macro instantiation
197+// CHECK-ERRORS-NEXT: .test1
198+// CHECK-ERRORS-NEXT: ^
199+
200+.macro test2 _a
201+.byte \_a
202+.endm
203+// CHECK: .byte 10
204+test2 10
205+
206+.macro test3 _a _b _c
207+.ascii "\_a \_b \_c \\_c"
208+.endm
209+
210+// CHECK: .ascii "1 2 3 \003"
211+test3 1, 2, 3
212+
213+// FIXME: test3 1, 2 3 should be treated like test 1, 2, 3
214+
215+// FIXME: remove the n argument from the remaining test3 examples
216+// CHECK: .ascii "1 (23) n \n"
217+test3 1, (2 3), n
218+
219+// CHECK: .ascii "1 (23) n \n"
220+test3 1 (2 3) n
221+
222+// CHECK: .ascii "1 2 n \n"
223+test3 1 2 n
224+
225+.macro test5 _a
226+.globl \_a
227+.endm
228+
229+// CHECK: .globl zed1
230+test5 zed1
231+
232+.macro test6 $a
233+.globl \$a
234+.endm
235+
236+// CHECK: .globl zed2
237+test6 zed2
238+
239+.macro test7 .a
240+.globl \.a
241+.endm
242+
243+// CHECK: .globl zed3
244+test7 zed3
245+
246+.macro test8 _a, _b, _c
247+.ascii "\_a,\_b,\_c"
248+.endm
249+
250+.macro test9 _a _b _c
251+.ascii "\_a \_b \_c"
252+.endm
253+
254+// CHECK: .ascii "a,b,c"
255+test8 a, b, c
256+// CHECK: .ascii "%1,%2,%3"
257+test8 %1 %2 %3 #a comment
258+// CHECK: .ascii "x-y,z,1"
259+test8 x - y z 1
260+// CHECK: .ascii "1 2 3"
261+test9 1, 2,3
262+
263+test8 1,2 3
264+// CHECK-ERRORS: error: macro argument '_c' is missing
265+// CHECK-ERRORS-NEXT: test8 1,2 3
266+// CHECK-ERRORS-NEXT:           ^
267+
268+test8 1 2, 3
269+// CHECK-ERRORS: error: expected ' ' for macro argument separator
270+// CHECK-ERRORS-NEXT:test8 1 2, 3
271+// CHECK-ERRORS-NEXT:         ^
272