Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f23d231

Browse files
committedMay 14, 2021
Add tests where asm! is properly in unsafe block
1 parent 116bc6d commit f23d231

File tree

7 files changed

+235
-26
lines changed

7 files changed

+235
-26
lines changed
 

‎src/test/ui/asm/bad-arch.stderr renamed to ‎src/test/ui/asm/bad-arch.mirunsafeck.stderr

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

77
error[E0472]: inline assembly is unsupported on this target
8-
--> $DIR/bad-arch.rs:25:1
8+
--> $DIR/bad-arch.rs:27:1
99
|
1010
LL | global_asm!("");
1111
| ^^^^^^^^^^^^^^^^

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// compile-flags: --target sparc-unknown-linux-gnu
22
// needs-llvm-components: sparc
3+
// revisions: mirunsafeck thirunsafeck
4+
// [thirunsafeck]compile-flags: -Z thir-unsafeck
35

46
#![feature(no_core, lang_items, rustc_attrs)]
57
#![no_core]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0472]: inline assembly is unsupported on this target
2+
--> $DIR/bad-arch.rs:22:9
3+
|
4+
LL | asm!("");
5+
| ^^^^^^^^^
6+
7+
error[E0472]: inline assembly is unsupported on this target
8+
--> $DIR/bad-arch.rs:27:1
9+
|
10+
LL | global_asm!("");
11+
| ^^^^^^^^^^^^^^^^
12+
|
13+
= note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
error: aborting due to 2 previous errors
16+

‎src/test/ui/asm/bad-template.stderr renamed to ‎src/test/ui/asm/bad-template.mirunsafeck.stderr

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: invalid reference to argument at index 0
2-
--> $DIR/bad-template.rs:8:15
2+
--> $DIR/bad-template.rs:10:15
33
|
44
LL | asm!("{}");
55
| ^^ from here
66
|
77
= note: no arguments were given
88

99
error: invalid reference to argument at index 1
10-
--> $DIR/bad-template.rs:10:15
10+
--> $DIR/bad-template.rs:12:15
1111
|
1212
LL | asm!("{1}", in(reg) foo);
1313
| ^^^ from here
1414
|
1515
= note: there is 1 argument
1616

1717
error: argument never used
18-
--> $DIR/bad-template.rs:10:21
18+
--> $DIR/bad-template.rs:12:21
1919
|
2020
LL | asm!("{1}", in(reg) foo);
2121
| ^^^^^^^^^^^ argument never used
2222
|
2323
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
2424

2525
error: there is no argument named `a`
26-
--> $DIR/bad-template.rs:13:15
26+
--> $DIR/bad-template.rs:15:15
2727
|
2828
LL | asm!("{a}");
2929
| ^^^
3030

3131
error: invalid reference to argument at index 0
32-
--> $DIR/bad-template.rs:15:15
32+
--> $DIR/bad-template.rs:17:15
3333
|
3434
LL | asm!("{}", a = in(reg) foo);
3535
| ^^ --------------- named argument
@@ -38,37 +38,37 @@ LL | asm!("{}", a = in(reg) foo);
3838
|
3939
= note: no positional arguments were given
4040
note: named arguments cannot be referenced by position
41-
--> $DIR/bad-template.rs:15:20
41+
--> $DIR/bad-template.rs:17:20
4242
|
4343
LL | asm!("{}", a = in(reg) foo);
4444
| ^^^^^^^^^^^^^^^
4545

4646
error: named argument never used
47-
--> $DIR/bad-template.rs:15:20
47+
--> $DIR/bad-template.rs:17:20
4848
|
4949
LL | asm!("{}", a = in(reg) foo);
5050
| ^^^^^^^^^^^^^^^ named argument never used
5151
|
5252
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
5353

5454
error: invalid reference to argument at index 1
55-
--> $DIR/bad-template.rs:18:15
55+
--> $DIR/bad-template.rs:20:15
5656
|
5757
LL | asm!("{1}", a = in(reg) foo);
5858
| ^^^ from here
5959
|
6060
= note: no positional arguments were given
6161

6262
error: named argument never used
63-
--> $DIR/bad-template.rs:18:21
63+
--> $DIR/bad-template.rs:20:21
6464
|
6565
LL | asm!("{1}", a = in(reg) foo);
6666
| ^^^^^^^^^^^^^^^ named argument never used
6767
|
6868
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
6969

7070
error: invalid reference to argument at index 0
71-
--> $DIR/bad-template.rs:21:15
71+
--> $DIR/bad-template.rs:23:15
7272
|
7373
LL | asm!("{}", in("eax") foo);
7474
| ^^ ------------- explicit register argument
@@ -77,19 +77,19 @@ LL | asm!("{}", in("eax") foo);
7777
|
7878
= note: no positional arguments were given
7979
note: explicit register arguments cannot be used in the asm template
80-
--> $DIR/bad-template.rs:21:20
80+
--> $DIR/bad-template.rs:23:20
8181
|
8282
LL | asm!("{}", in("eax") foo);
8383
| ^^^^^^^^^^^^^
8484

8585
error: asm template modifier must be a single character
86-
--> $DIR/bad-template.rs:23:17
86+
--> $DIR/bad-template.rs:25:17
8787
|
8888
LL | asm!("{:foo}", in(reg) foo);
8989
| ^^^
9090

9191
error: multiple unused asm arguments
92-
--> $DIR/bad-template.rs:25:18
92+
--> $DIR/bad-template.rs:27:18
9393
|
9494
LL | asm!("", in(reg) 0, in(reg) 1);
9595
| ^^^^^^^^^ ^^^^^^^^^ argument never used
@@ -99,37 +99,37 @@ LL | asm!("", in(reg) 0, in(reg) 1);
9999
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
100100

101101
error: invalid reference to argument at index 0
102-
--> $DIR/bad-template.rs:31:14
102+
--> $DIR/bad-template.rs:33:14
103103
|
104104
LL | global_asm!("{}");
105105
| ^^ from here
106106
|
107107
= note: no arguments were given
108108

109109
error: invalid reference to argument at index 1
110-
--> $DIR/bad-template.rs:33:14
110+
--> $DIR/bad-template.rs:35:14
111111
|
112112
LL | global_asm!("{1}", const FOO);
113113
| ^^^ from here
114114
|
115115
= note: there is 1 argument
116116

117117
error: argument never used
118-
--> $DIR/bad-template.rs:33:20
118+
--> $DIR/bad-template.rs:35:20
119119
|
120120
LL | global_asm!("{1}", const FOO);
121121
| ^^^^^^^^^ argument never used
122122
|
123123
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
124124

125125
error: there is no argument named `a`
126-
--> $DIR/bad-template.rs:36:14
126+
--> $DIR/bad-template.rs:38:14
127127
|
128128
LL | global_asm!("{a}");
129129
| ^^^
130130

131131
error: invalid reference to argument at index 0
132-
--> $DIR/bad-template.rs:38:14
132+
--> $DIR/bad-template.rs:40:14
133133
|
134134
LL | global_asm!("{}", a = const FOO);
135135
| ^^ ------------- named argument
@@ -138,43 +138,43 @@ LL | global_asm!("{}", a = const FOO);
138138
|
139139
= note: no positional arguments were given
140140
note: named arguments cannot be referenced by position
141-
--> $DIR/bad-template.rs:38:19
141+
--> $DIR/bad-template.rs:40:19
142142
|
143143
LL | global_asm!("{}", a = const FOO);
144144
| ^^^^^^^^^^^^^
145145

146146
error: named argument never used
147-
--> $DIR/bad-template.rs:38:19
147+
--> $DIR/bad-template.rs:40:19
148148
|
149149
LL | global_asm!("{}", a = const FOO);
150150
| ^^^^^^^^^^^^^ named argument never used
151151
|
152152
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
153153

154154
error: invalid reference to argument at index 1
155-
--> $DIR/bad-template.rs:41:14
155+
--> $DIR/bad-template.rs:43:14
156156
|
157157
LL | global_asm!("{1}", a = const FOO);
158158
| ^^^ from here
159159
|
160160
= note: no positional arguments were given
161161

162162
error: named argument never used
163-
--> $DIR/bad-template.rs:41:20
163+
--> $DIR/bad-template.rs:43:20
164164
|
165165
LL | global_asm!("{1}", a = const FOO);
166166
| ^^^^^^^^^^^^^ named argument never used
167167
|
168168
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
169169

170170
error: asm template modifier must be a single character
171-
--> $DIR/bad-template.rs:44:16
171+
--> $DIR/bad-template.rs:46:16
172172
|
173173
LL | global_asm!("{:foo}", const FOO);
174174
| ^^^
175175

176176
error: multiple unused asm arguments
177-
--> $DIR/bad-template.rs:46:17
177+
--> $DIR/bad-template.rs:48:17
178178
|
179179
LL | global_asm!("", const FOO, const FOO);
180180
| ^^^^^^^^^ ^^^^^^^^^ argument never used

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// only-x86_64
2+
// revisions: mirunsafeck thirunsafeck
3+
// [thirunsafeck]compile-flags: -Z thir-unsafeck
24

35
#![feature(asm, global_asm)]
46

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
error: invalid reference to argument at index 0
2+
--> $DIR/bad-template.rs:10:15
3+
|
4+
LL | asm!("{}");
5+
| ^^ from here
6+
|
7+
= note: no arguments were given
8+
9+
error: invalid reference to argument at index 1
10+
--> $DIR/bad-template.rs:12:15
11+
|
12+
LL | asm!("{1}", in(reg) foo);
13+
| ^^^ from here
14+
|
15+
= note: there is 1 argument
16+
17+
error: argument never used
18+
--> $DIR/bad-template.rs:12:21
19+
|
20+
LL | asm!("{1}", in(reg) foo);
21+
| ^^^^^^^^^^^ argument never used
22+
|
23+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
24+
25+
error: there is no argument named `a`
26+
--> $DIR/bad-template.rs:15:15
27+
|
28+
LL | asm!("{a}");
29+
| ^^^
30+
31+
error: invalid reference to argument at index 0
32+
--> $DIR/bad-template.rs:17:15
33+
|
34+
LL | asm!("{}", a = in(reg) foo);
35+
| ^^ --------------- named argument
36+
| |
37+
| from here
38+
|
39+
= note: no positional arguments were given
40+
note: named arguments cannot be referenced by position
41+
--> $DIR/bad-template.rs:17:20
42+
|
43+
LL | asm!("{}", a = in(reg) foo);
44+
| ^^^^^^^^^^^^^^^
45+
46+
error: named argument never used
47+
--> $DIR/bad-template.rs:17:20
48+
|
49+
LL | asm!("{}", a = in(reg) foo);
50+
| ^^^^^^^^^^^^^^^ named argument never used
51+
|
52+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
53+
54+
error: invalid reference to argument at index 1
55+
--> $DIR/bad-template.rs:20:15
56+
|
57+
LL | asm!("{1}", a = in(reg) foo);
58+
| ^^^ from here
59+
|
60+
= note: no positional arguments were given
61+
62+
error: named argument never used
63+
--> $DIR/bad-template.rs:20:21
64+
|
65+
LL | asm!("{1}", a = in(reg) foo);
66+
| ^^^^^^^^^^^^^^^ named argument never used
67+
|
68+
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
69+
70+
error: invalid reference to argument at index 0
71+
--> $DIR/bad-template.rs:23:15
72+
|
73+
LL | asm!("{}", in("eax") foo);
74+
| ^^ ------------- explicit register argument
75+
| |
76+
| from here
77+
|
78+
= note: no positional arguments were given
79+
note: explicit register arguments cannot be used in the asm template
80+
--> $DIR/bad-template.rs:23:20
81+
|
82+
LL | asm!("{}", in("eax") foo);
83+
| ^^^^^^^^^^^^^
84+
85+
error: asm template modifier must be a single character
86+
--> $DIR/bad-template.rs:25:17
87+
|
88+
LL | asm!("{:foo}", in(reg) foo);
89+
| ^^^
90+
91+
error: multiple unused asm arguments
92+
--> $DIR/bad-template.rs:27:18
93+
|
94+
LL | asm!("", in(reg) 0, in(reg) 1);
95+
| ^^^^^^^^^ ^^^^^^^^^ argument never used
96+
| |
97+
| argument never used
98+
|
99+
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
100+
101+
error: invalid reference to argument at index 0
102+
--> $DIR/bad-template.rs:33: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:35: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:35: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:38:14
127+
|
128+
LL | global_asm!("{a}");
129+
| ^^^
130+
131+
error: invalid reference to argument at index 0
132+
--> $DIR/bad-template.rs:40: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:40:19
142+
|
143+
LL | global_asm!("{}", a = const FOO);
144+
| ^^^^^^^^^^^^^
145+
146+
error: named argument never used
147+
--> $DIR/bad-template.rs:40: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:43: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:43: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:46:16
172+
|
173+
LL | global_asm!("{:foo}", const FOO);
174+
| ^^^
175+
176+
error: multiple unused asm arguments
177+
--> $DIR/bad-template.rs:48: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
187+

‎src/test/ui/asm/const.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// min-llvm-version: 10.0.1
22
// only-x86_64
33
// run-pass
4+
// revisions: mirunsafeck thirunsafeck
5+
// [thirunsafeck]compile-flags: -Z thir-unsafeck
46

57
#![feature(asm, global_asm)]
68

0 commit comments

Comments
 (0)
Please sign in to comment.