Skip to content

Commit e0ed0f4

Browse files
committed
Update tests for sym support in global_asm!
1 parent c1fa773 commit e0ed0f4

11 files changed

+114
-58
lines changed

src/test/assembly/asm/global_asm.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
// assembly-output: emit-asm
33
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
44

5-
#![feature(asm_const)]
5+
#![feature(asm_const, asm_sym)]
66
#![crate_type = "rlib"]
77

88
use std::arch::global_asm;
99

10+
#[no_mangle]
11+
fn my_func() {}
12+
13+
#[no_mangle]
14+
static MY_STATIC: i32 = 0;
15+
1016
// CHECK: mov eax, eax
1117
global_asm!("mov eax, eax");
1218
// CHECK: mov ebx, 5
1319
global_asm!("mov ebx, {}", const 5);
1420
// CHECK: mov ecx, 5
1521
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
22+
// CHECK: call my_func
23+
global_asm!("call {}", sym my_func);
24+
// CHECK: lea rax, [rip + MY_STATIC]
25+
global_asm!("lea rax, [rip + {}]", sym MY_STATIC);

src/test/ui/asm/aarch64/parse-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
asm!("{}", in(reg) foo => bar);
3030
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
3131
asm!("{}", sym foo + bar);
32-
//~^ ERROR argument to `sym` must be a path expression
32+
//~^ ERROR expected a path for argument to `sym`
3333
asm!("", options(foo));
3434
//~^ ERROR expected one of
3535
asm!("", options(nomem foo));

src/test/ui/asm/aarch64/parse-error.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
5858
LL | asm!("{}", in(reg) foo => bar);
5959
| ^^ expected one of 7 possible tokens
6060

61-
error: argument to `sym` must be a path expression
61+
error: expected a path for argument to `sym`
6262
--> $DIR/parse-error.rs:31:24
6363
|
6464
LL | asm!("{}", sym foo + bar);
@@ -350,17 +350,17 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
350350
|
351351
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
352352

353-
error: expected one of `clobber_abi`, `const`, or `options`, found `""`
353+
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `""`
354354
--> $DIR/parse-error.rs:126:28
355355
|
356356
LL | global_asm!("", options(), "");
357-
| ^^ expected one of `clobber_abi`, `const`, or `options`
357+
| ^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
358358

359-
error: expected one of `clobber_abi`, `const`, or `options`, found `"{}"`
359+
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `"{}"`
360360
--> $DIR/parse-error.rs:128:30
361361
|
362362
LL | global_asm!("{}", const FOO, "{}", const FOO);
363-
| ^^^^ expected one of `clobber_abi`, `const`, or `options`
363+
| ^^^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
364364

365365
error: asm template must be a string literal
366366
--> $DIR/parse-error.rs:130:13

src/test/ui/asm/aarch64/type-check-2.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(repr_simd, never_type, asm_sym)]
44

5-
use std::arch::asm;
5+
use std::arch::{asm, global_asm};
66

77
#[repr(simd)]
88
#[derive(Clone, Copy)]
@@ -39,9 +39,7 @@ fn main() {
3939
asm!("{}", sym S);
4040
asm!("{}", sym main);
4141
asm!("{}", sym C);
42-
//~^ ERROR asm `sym` operand must point to a fn or static
43-
asm!("{}", sym x);
44-
//~^ ERROR asm `sym` operand must point to a fn or static
42+
//~^ ERROR invalid `sym` operand
4543

4644
// Register operands must be Copy
4745

@@ -84,3 +82,12 @@ fn main() {
8482
asm!("{}", in(reg) u);
8583
}
8684
}
85+
86+
// Sym operands must point to a function or static
87+
88+
const C: i32 = 0;
89+
static S: i32 = 0;
90+
global_asm!("{}", sym S);
91+
global_asm!("{}", sym main);
92+
global_asm!("{}", sym C);
93+
//~^ ERROR invalid `sym` operand

src/test/ui/asm/aarch64/type-check-2.stderr

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error: arguments for inline assembly must be copyable
2-
--> $DIR/type-check-2.rs:48:31
2+
--> $DIR/type-check-2.rs:46:31
33
|
44
LL | asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `SimdNonCopy` does not implement the Copy trait
88

9-
error: cannot use value of type `[closure@$DIR/type-check-2.rs:60:28: 60:38]` for inline assembly
10-
--> $DIR/type-check-2.rs:60:28
9+
error: cannot use value of type `[closure@$DIR/type-check-2.rs:58:28: 58:38]` for inline assembly
10+
--> $DIR/type-check-2.rs:58:28
1111
|
1212
LL | asm!("{}", in(reg) |x: i32| x);
1313
| ^^^^^^^^^^
1414
|
1515
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
1616

1717
error: cannot use value of type `Vec<i32>` for inline assembly
18-
--> $DIR/type-check-2.rs:62:28
18+
--> $DIR/type-check-2.rs:60:28
1919
|
2020
LL | asm!("{}", in(reg) vec![0]);
2121
| ^^^^^^^
@@ -24,48 +24,52 @@ LL | asm!("{}", in(reg) vec![0]);
2424
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

2626
error: cannot use value of type `(i32, i32, i32)` for inline assembly
27-
--> $DIR/type-check-2.rs:64:28
27+
--> $DIR/type-check-2.rs:62:28
2828
|
2929
LL | asm!("{}", in(reg) (1, 2, 3));
3030
| ^^^^^^^^^
3131
|
3232
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
3333

3434
error: cannot use value of type `[i32; 3]` for inline assembly
35-
--> $DIR/type-check-2.rs:66:28
35+
--> $DIR/type-check-2.rs:64:28
3636
|
3737
LL | asm!("{}", in(reg) [1, 2, 3]);
3838
| ^^^^^^^^^
3939
|
4040
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
4141

4242
error: cannot use value of type `fn() {main}` for inline assembly
43-
--> $DIR/type-check-2.rs:74:31
43+
--> $DIR/type-check-2.rs:72:31
4444
|
4545
LL | asm!("{}", inout(reg) f);
4646
| ^
4747
|
4848
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
4949

5050
error: cannot use value of type `&mut i32` for inline assembly
51-
--> $DIR/type-check-2.rs:77:31
51+
--> $DIR/type-check-2.rs:75:31
5252
|
5353
LL | asm!("{}", inout(reg) r);
5454
| ^
5555
|
5656
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
5757

58-
error: asm `sym` operand must point to a fn or static
59-
--> $DIR/type-check-2.rs:41:24
58+
error: invalid `sym` operand
59+
--> $DIR/type-check-2.rs:41:20
6060
|
6161
LL | asm!("{}", sym C);
62-
| ^
62+
| ^^^^^ is an `i32`
63+
|
64+
= help: `sym` operands must refer to either a function or a static
6365

64-
error: asm `sym` operand must point to a fn or static
65-
--> $DIR/type-check-2.rs:43:24
66+
error: invalid `sym` operand
67+
--> $DIR/type-check-2.rs:92:19
68+
|
69+
LL | global_asm!("{}", sym C);
70+
| ^^^^^ is an `i32`
6671
|
67-
LL | asm!("{}", sym x);
68-
| ^
72+
= help: `sym` operands must refer to either a function or a static
6973

7074
error[E0381]: use of possibly-uninitialized variable: `x`
7175
--> $DIR/type-check-2.rs:19:28

src/test/ui/asm/type-check-1.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ignore-spirv
44
// ignore-wasm32
55

6-
#![feature(asm_const)]
6+
#![feature(asm_const, asm_sym)]
77

88
use std::arch::{asm, global_asm};
99

@@ -44,6 +44,8 @@ fn main() {
4444
asm!("{}", const const_bar(0));
4545
asm!("{}", const const_bar(x));
4646
//~^ ERROR attempt to use a non-constant value in a constant
47+
asm!("{}", sym x);
48+
//~^ ERROR invalid `sym` operand
4749

4850
// Const operands must be integers and must be constants.
4951

@@ -59,6 +61,11 @@ fn main() {
5961
}
6062
}
6163

64+
unsafe fn generic<T>() {
65+
asm!("{}", sym generic::<T>);
66+
//~^ generic parameters may not be used in const operations
67+
}
68+
6269
// Const operands must be integers and must be constants.
6370

6471
global_asm!("{}", const 0);

src/test/ui/asm/type-check-1.stderr

+23-6
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,31 @@ LL | let x = 0;
2525
LL | asm!("{}", const const_bar(x));
2626
| ^ non-constant value
2727

28+
error: invalid `sym` operand
29+
--> $DIR/type-check-1.rs:47:24
30+
|
31+
LL | asm!("{}", sym x);
32+
| ^ is a local variable
33+
|
34+
= help: `sym` operands must refer to either a function or a static
35+
36+
error: generic parameters may not be used in const operations
37+
--> $DIR/type-check-1.rs:65:30
38+
|
39+
LL | asm!("{}", sym generic::<T>);
40+
| ^ cannot perform const operation using `T`
41+
|
42+
= note: type parameters may not be used in const expressions
43+
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
44+
2845
error[E0308]: mismatched types
29-
--> $DIR/type-check-1.rs:53:26
46+
--> $DIR/type-check-1.rs:55:26
3047
|
3148
LL | asm!("{}", const 0f32);
3249
| ^^^^ expected integer, found `f32`
3350

3451
error[E0308]: mismatched types
35-
--> $DIR/type-check-1.rs:55:26
52+
--> $DIR/type-check-1.rs:57:26
3653
|
3754
LL | asm!("{}", const 0 as *mut u8);
3855
| ^^^^^^^^^^^^ expected integer, found *-ptr
@@ -41,7 +58,7 @@ LL | asm!("{}", const 0 as *mut u8);
4158
found raw pointer `*mut u8`
4259

4360
error[E0308]: mismatched types
44-
--> $DIR/type-check-1.rs:57:26
61+
--> $DIR/type-check-1.rs:59:26
4562
|
4663
LL | asm!("{}", const &0);
4764
| ^^ expected integer, found `&{integer}`
@@ -92,21 +109,21 @@ LL | asm!("{}", inout(reg) v[..]);
92109
= note: all inline asm arguments must have a statically known size
93110

94111
error[E0308]: mismatched types
95-
--> $DIR/type-check-1.rs:67:25
112+
--> $DIR/type-check-1.rs:74:25
96113
|
97114
LL | global_asm!("{}", const 0f32);
98115
| ^^^^ expected integer, found `f32`
99116

100117
error[E0308]: mismatched types
101-
--> $DIR/type-check-1.rs:69:25
118+
--> $DIR/type-check-1.rs:76:25
102119
|
103120
LL | global_asm!("{}", const 0 as *mut u8);
104121
| ^^^^^^^^^^^^ expected integer, found *-ptr
105122
|
106123
= note: expected type `{integer}`
107124
found raw pointer `*mut u8`
108125

109-
error: aborting due to 13 previous errors
126+
error: aborting due to 15 previous errors
110127

111128
Some errors have detailed explanations: E0277, E0308, E0435.
112129
For more information about an error, try `rustc --explain E0277`.

src/test/ui/asm/x86_64/parse-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
asm!("{}", in(reg) foo => bar);
3030
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
3131
asm!("{}", sym foo + bar);
32-
//~^ ERROR argument to `sym` must be a path expression
32+
//~^ ERROR expected a path for argument to `sym`
3333
asm!("", options(foo));
3434
//~^ ERROR expected one of
3535
asm!("", options(nomem foo));

src/test/ui/asm/x86_64/parse-error.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
5858
LL | asm!("{}", in(reg) foo => bar);
5959
| ^^ expected one of 7 possible tokens
6060

61-
error: argument to `sym` must be a path expression
61+
error: expected a path for argument to `sym`
6262
--> $DIR/parse-error.rs:31:24
6363
|
6464
LL | asm!("{}", sym foo + bar);
@@ -362,17 +362,17 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
362362
|
363363
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
364364

365-
error: expected one of `clobber_abi`, `const`, or `options`, found `""`
365+
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `""`
366366
--> $DIR/parse-error.rs:130:28
367367
|
368368
LL | global_asm!("", options(), "");
369-
| ^^ expected one of `clobber_abi`, `const`, or `options`
369+
| ^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
370370

371-
error: expected one of `clobber_abi`, `const`, or `options`, found `"{}"`
371+
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `"{}"`
372372
--> $DIR/parse-error.rs:132:30
373373
|
374374
LL | global_asm!("{}", const FOO, "{}", const FOO);
375-
| ^^^^ expected one of `clobber_abi`, `const`, or `options`
375+
| ^^^^ expected one of `clobber_abi`, `const`, `options`, or `sym`
376376

377377
error: asm template must be a string literal
378378
--> $DIR/parse-error.rs:134:13

src/test/ui/asm/x86_64/type-check-2.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![feature(repr_simd, never_type, asm_sym)]
44

5-
use std::arch::asm;
5+
use std::arch::{asm, global_asm};
66

77
#[repr(simd)]
88
struct SimdNonCopy(f32, f32, f32, f32);
@@ -35,9 +35,7 @@ fn main() {
3535
asm!("{}", sym S);
3636
asm!("{}", sym main);
3737
asm!("{}", sym C);
38-
//~^ ERROR asm `sym` operand must point to a fn or static
39-
asm!("{}", sym x);
40-
//~^ ERROR asm `sym` operand must point to a fn or static
38+
//~^ ERROR invalid `sym` operand
4139

4240
// Register operands must be Copy
4341

@@ -80,3 +78,12 @@ fn main() {
8078
asm!("{}", in(reg) u);
8179
}
8280
}
81+
82+
// Sym operands must point to a function or static
83+
84+
const C: i32 = 0;
85+
static S: i32 = 0;
86+
global_asm!("{}", sym S);
87+
global_asm!("{}", sym main);
88+
global_asm!("{}", sym C);
89+
//~^ ERROR invalid `sym` operand

0 commit comments

Comments
 (0)