Skip to content

Commit 5a229e0

Browse files
committed
Add tests for global_asm!
1 parent 5918ee4 commit 5a229e0

20 files changed

+455
-32
lines changed

src/test/assembly/asm/global_asm.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// min-llvm-version: 10.0.1
2+
// only-x86_64
3+
// assembly-output: emit-asm
4+
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
5+
6+
#![feature(asm, global_asm)]
7+
#![crate_type = "rlib"]
8+
9+
// CHECK: mov eax, eax
10+
global_asm!("mov eax, eax");
11+
// CHECK: mov ebx, 5
12+
global_asm!("mov ebx, {}", const 5);
13+
// CHECK: mov ecx, 5
14+
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));

src/test/ui/asm/bad-arch.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
macro_rules! asm {
99
() => {};
1010
}
11+
#[rustc_builtin_macro]
12+
macro_rules! global_asm {
13+
() => {};
14+
}
1115
#[lang = "sized"]
1216
trait Sized {}
1317

@@ -17,3 +21,6 @@ fn main() {
1721
//~^ ERROR asm! is unsupported on this target
1822
}
1923
}
24+
25+
global_asm!("");
26+
//~^ ERROR asm! is unsupported on this target

src/test/ui/asm/bad-arch.stderr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
error[E0472]: asm! is unsupported on this target
2-
--> $DIR/bad-arch.rs:16:9
2+
--> $DIR/bad-arch.rs:20:9
33
|
44
LL | asm!("");
55
| ^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error[E0472]: asm! is unsupported on this target
8+
--> $DIR/bad-arch.rs:25:1
9+
|
10+
LL | global_asm!("");
11+
| ^^^^^^^^^^^^^^^^
12+
|
13+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
error: aborting due to 2 previous errors
816

src/test/ui/asm/bad-options.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// only-x86_64
22

3-
#![feature(asm)]
3+
#![feature(asm, global_asm)]
44

55
fn main() {
66
let mut foo = 0;
@@ -16,3 +16,16 @@ fn main() {
1616
//~^ ERROR asm outputs are not allowed with the `noreturn` option
1717
}
1818
}
19+
20+
global_asm!("", options(nomem));
21+
//~^ ERROR expected one of
22+
global_asm!("", options(readonly));
23+
//~^ ERROR expected one of
24+
global_asm!("", options(noreturn));
25+
//~^ ERROR expected one of
26+
global_asm!("", options(pure));
27+
//~^ ERROR expected one of
28+
global_asm!("", options(nostack));
29+
//~^ ERROR expected one of
30+
global_asm!("", options(preserves_flags));
31+
//~^ ERROR expected one of

src/test/ui/asm/bad-options.stderr

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,41 @@ error: asm outputs are not allowed with the `noreturn` option
2828
LL | asm!("{}", out(reg) foo, options(noreturn));
2929
| ^^^^^^^^^^^^
3030

31-
error: aborting due to 5 previous errors
31+
error: expected one of `)` or `att_syntax`, found `nomem`
32+
--> $DIR/bad-options.rs:20:25
33+
|
34+
LL | global_asm!("", options(nomem));
35+
| ^^^^^ expected one of `)` or `att_syntax`
36+
37+
error: expected one of `)` or `att_syntax`, found `readonly`
38+
--> $DIR/bad-options.rs:22:25
39+
|
40+
LL | global_asm!("", options(readonly));
41+
| ^^^^^^^^ expected one of `)` or `att_syntax`
42+
43+
error: expected one of `)` or `att_syntax`, found `noreturn`
44+
--> $DIR/bad-options.rs:24:25
45+
|
46+
LL | global_asm!("", options(noreturn));
47+
| ^^^^^^^^ expected one of `)` or `att_syntax`
48+
49+
error: expected one of `)` or `att_syntax`, found `pure`
50+
--> $DIR/bad-options.rs:26:25
51+
|
52+
LL | global_asm!("", options(pure));
53+
| ^^^^ expected one of `)` or `att_syntax`
54+
55+
error: expected one of `)` or `att_syntax`, found `nostack`
56+
--> $DIR/bad-options.rs:28:25
57+
|
58+
LL | global_asm!("", options(nostack));
59+
| ^^^^^^^ expected one of `)` or `att_syntax`
60+
61+
error: expected one of `)` or `att_syntax`, found `preserves_flags`
62+
--> $DIR/bad-options.rs:30:25
63+
|
64+
LL | global_asm!("", options(preserves_flags));
65+
| ^^^^^^^^^^^^^^^ expected one of `)` or `att_syntax`
66+
67+
error: aborting due to 11 previous errors
3268

src/test/ui/asm/bad-template.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// only-x86_64
22

3-
#![feature(asm)]
3+
#![feature(asm, global_asm)]
44

55
fn main() {
66
let mut foo = 0;
@@ -26,3 +26,22 @@ fn main() {
2626
//~^ ERROR multiple unused asm arguments
2727
}
2828
}
29+
30+
const FOO: i32 = 1;
31+
global_asm!("{}");
32+
//~^ ERROR invalid reference to argument at index 0
33+
global_asm!("{1}", const FOO);
34+
//~^ ERROR invalid reference to argument at index 1
35+
//~^^ ERROR argument never used
36+
global_asm!("{a}");
37+
//~^ ERROR there is no argument named `a`
38+
global_asm!("{}", a = const FOO);
39+
//~^ ERROR invalid reference to argument at index 0
40+
//~^^ ERROR argument never used
41+
global_asm!("{1}", a = const FOO);
42+
//~^ ERROR invalid reference to argument at index 1
43+
//~^^ ERROR named argument never used
44+
global_asm!("{:foo}", const FOO);
45+
//~^ ERROR asm template modifier must be a single character
46+
global_asm!("", const FOO, const FOO);
47+
//~^ ERROR multiple unused asm arguments

src/test/ui/asm/bad-template.stderr

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,90 @@ LL | asm!("", in(reg) 0, in(reg) 1);
9898
|
9999
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
100100

101-
error: aborting due to 11 previous errors
101+
error: invalid reference to argument at index 0
102+
--> $DIR/bad-template.rs:31:14
103+
|
104+
LL | global_asm!("{}");
105+
| ^^ from here
106+
|
107+
= note: no arguments were given
108+
109+
error: invalid reference to argument at index 1
110+
--> $DIR/bad-template.rs:33:14
111+
|
112+
LL | global_asm!("{1}", const FOO);
113+
| ^^^ from here
114+
|
115+
= note: there is 1 argument
116+
117+
error: argument never used
118+
--> $DIR/bad-template.rs:33:20
119+
|
120+
LL | global_asm!("{1}", const FOO);
121+
| ^^^^^^^^^ argument never used
122+
|
123+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
124+
125+
error: there is no argument named `a`
126+
--> $DIR/bad-template.rs:36:14
127+
|
128+
LL | global_asm!("{a}");
129+
| ^^^
130+
131+
error: invalid reference to argument at index 0
132+
--> $DIR/bad-template.rs:38:14
133+
|
134+
LL | global_asm!("{}", a = const FOO);
135+
| ^^ ------------- named argument
136+
| |
137+
| from here
138+
|
139+
= note: no positional arguments were given
140+
note: named arguments cannot be referenced by position
141+
--> $DIR/bad-template.rs:38:19
142+
|
143+
LL | global_asm!("{}", a = const FOO);
144+
| ^^^^^^^^^^^^^
145+
146+
error: named argument never used
147+
--> $DIR/bad-template.rs:38:19
148+
|
149+
LL | global_asm!("{}", a = const FOO);
150+
| ^^^^^^^^^^^^^ named argument never used
151+
|
152+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
153+
154+
error: invalid reference to argument at index 1
155+
--> $DIR/bad-template.rs:41:14
156+
|
157+
LL | global_asm!("{1}", a = const FOO);
158+
| ^^^ from here
159+
|
160+
= note: no positional arguments were given
161+
162+
error: named argument never used
163+
--> $DIR/bad-template.rs:41:20
164+
|
165+
LL | global_asm!("{1}", a = const FOO);
166+
| ^^^^^^^^^^^^^ named argument never used
167+
|
168+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
169+
170+
error: asm template modifier must be a single character
171+
--> $DIR/bad-template.rs:44:16
172+
|
173+
LL | global_asm!("{:foo}", const FOO);
174+
| ^^^
175+
176+
error: multiple unused asm arguments
177+
--> $DIR/bad-template.rs:46:17
178+
|
179+
LL | global_asm!("", const FOO, const FOO);
180+
| ^^^^^^^^^ ^^^^^^^^^ argument never used
181+
| |
182+
| argument never used
183+
|
184+
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
185+
186+
error: aborting due to 21 previous errors
102187

src/test/ui/asm/const.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// only-x86_64
33
// run-pass
44

5-
#![feature(asm)]
5+
#![feature(asm, global_asm)]
66

77
fn const_generic<const X: usize>() -> usize {
88
unsafe {
@@ -34,3 +34,7 @@ fn main() {
3434
let d = const_generic::<5>();
3535
assert_eq!(d, 5);
3636
}
37+
38+
global_asm!("mov eax, {}", const 5);
39+
global_asm!("mov eax, {}", const constfn(5));
40+
global_asm!("mov eax, {}", const constfn(5) + constfn(5));

src/test/ui/asm/duplicate-options.fixed

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// only-x86_64
22
// run-rustfix
33

4-
#![feature(asm)]
4+
#![feature(asm, global_asm)]
55

66
fn main() {
77
unsafe {
@@ -24,3 +24,6 @@ fn main() {
2424
);
2525
}
2626
}
27+
28+
global_asm!("", options(att_syntax, ));
29+
//~^ ERROR the `att_syntax` option was already provided

src/test/ui/asm/duplicate-options.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// only-x86_64
22
// run-rustfix
33

4-
#![feature(asm)]
4+
#![feature(asm, global_asm)]
55

66
fn main() {
77
unsafe {
@@ -24,3 +24,6 @@ fn main() {
2424
);
2525
}
2626
}
27+
28+
global_asm!("", options(att_syntax, att_syntax));
29+
//~^ ERROR the `att_syntax` option was already provided

src/test/ui/asm/duplicate-options.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ error: the `noreturn` option was already provided
5252
LL | options(noreturn),
5353
| ^^^^^^^^ this option was already provided
5454

55-
error: aborting due to 9 previous errors
55+
error: the `att_syntax` option was already provided
56+
--> $DIR/duplicate-options.rs:28:37
57+
|
58+
LL | global_asm!("", options(att_syntax, att_syntax));
59+
| ^^^^^^^^^^ this option was already provided
60+
61+
error: aborting due to 10 previous errors
5662

src/test/ui/asm/inline-syntax.arm.stderr

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
error: unknown directive
2-
--> $DIR/inline-syntax.rs:25:15
2+
.intel_syntax noprefix
3+
^
4+
error: unknown directive
5+
.intel_syntax noprefix
6+
^
7+
error: unknown directive
8+
|
9+
note: instantiated into assembly here
10+
--> <inline asm>:1:1
11+
|
12+
LL | .intel_syntax noprefix
13+
| ^
14+
15+
error: unknown directive
16+
--> $DIR/inline-syntax.rs:29:15
317
|
418
LL | asm!(".intel_syntax noprefix", "nop");
519
| ^
@@ -11,7 +25,7 @@ LL | .intel_syntax noprefix
1125
| ^
1226

1327
error: unknown directive
14-
--> $DIR/inline-syntax.rs:28:15
28+
--> $DIR/inline-syntax.rs:32:15
1529
|
1630
LL | asm!(".intel_syntax aaa noprefix", "nop");
1731
| ^
@@ -23,7 +37,7 @@ LL | .intel_syntax aaa noprefix
2337
| ^
2438

2539
error: unknown directive
26-
--> $DIR/inline-syntax.rs:31:15
40+
--> $DIR/inline-syntax.rs:35:15
2741
|
2842
LL | asm!(".att_syntax noprefix", "nop");
2943
| ^
@@ -35,7 +49,7 @@ LL | .att_syntax noprefix
3549
| ^
3650

3751
error: unknown directive
38-
--> $DIR/inline-syntax.rs:34:15
52+
--> $DIR/inline-syntax.rs:38:15
3953
|
4054
LL | asm!(".att_syntax bbb noprefix", "nop");
4155
| ^
@@ -47,7 +61,7 @@ LL | .att_syntax bbb noprefix
4761
| ^
4862

4963
error: unknown directive
50-
--> $DIR/inline-syntax.rs:37:15
64+
--> $DIR/inline-syntax.rs:41:15
5165
|
5266
LL | asm!(".intel_syntax noprefix; nop");
5367
| ^
@@ -59,7 +73,7 @@ LL | .intel_syntax noprefix; nop
5973
| ^
6074

6175
error: unknown directive
62-
--> $DIR/inline-syntax.rs:43:13
76+
--> $DIR/inline-syntax.rs:47:13
6377
|
6478
LL | .intel_syntax noprefix
6579
| ^
@@ -70,5 +84,5 @@ note: instantiated into assembly here
7084
LL | .intel_syntax noprefix
7185
| ^
7286

73-
error: aborting due to 6 previous errors
87+
error: aborting due to 7 previous errors
7488

src/test/ui/asm/inline-syntax.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
macro_rules! asm {
1717
() => {};
1818
}
19+
#[rustc_builtin_macro]
20+
macro_rules! global_asm {
21+
() => {};
22+
}
1923

2024
#[lang = "sized"]
2125
trait Sized {}
@@ -47,3 +51,7 @@ pub fn main() {
4751
//[arm]~^^^^ ERROR unknown directive
4852
}
4953
}
54+
55+
global_asm!(".intel_syntax noprefix", "nop");
56+
//[x86_64]~^ WARN avoid using `.intel_syntax`
57+
// Assembler errors don't have line numbers, so no error on ARM

0 commit comments

Comments
 (0)