Skip to content

Commit

Permalink
Update tests for sym support in global_asm!
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Apr 4, 2022
1 parent c1fa773 commit e0ed0f4
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 58 deletions.
12 changes: 11 additions & 1 deletion src/test/assembly/asm/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
// assembly-output: emit-asm
// compile-flags: -C llvm-args=--x86-asm-syntax=intel

#![feature(asm_const)]
#![feature(asm_const, asm_sym)]
#![crate_type = "rlib"]

use std::arch::global_asm;

#[no_mangle]
fn my_func() {}

#[no_mangle]
static MY_STATIC: i32 = 0;

// CHECK: mov eax, eax
global_asm!("mov eax, eax");
// CHECK: mov ebx, 5
global_asm!("mov ebx, {}", const 5);
// CHECK: mov ecx, 5
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
// CHECK: call my_func
global_asm!("call {}", sym my_func);
// CHECK: lea rax, [rip + MY_STATIC]
global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/parse-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
asm!("{}", in(reg) foo => bar);
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
asm!("{}", sym foo + bar);
//~^ ERROR argument to `sym` must be a path expression
//~^ ERROR expected a path for argument to `sym`
asm!("", options(foo));
//~^ ERROR expected one of
asm!("", options(nomem foo));
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/asm/aarch64/parse-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
LL | asm!("{}", in(reg) foo => bar);
| ^^ expected one of 7 possible tokens

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

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

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

error: asm template must be a string literal
--> $DIR/parse-error.rs:130:13
Expand Down
15 changes: 11 additions & 4 deletions src/test/ui/asm/aarch64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

#[repr(simd)]
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -39,9 +39,7 @@ fn main() {
asm!("{}", sym S);
asm!("{}", sym main);
asm!("{}", sym C);
//~^ ERROR asm `sym` operand must point to a fn or static
asm!("{}", sym x);
//~^ ERROR asm `sym` operand must point to a fn or static
//~^ ERROR invalid `sym` operand

// Register operands must be Copy

Expand Down Expand Up @@ -84,3 +82,12 @@ fn main() {
asm!("{}", in(reg) u);
}
}

// Sym operands must point to a function or static

const C: i32 = 0;
static S: i32 = 0;
global_asm!("{}", sym S);
global_asm!("{}", sym main);
global_asm!("{}", sym C);
//~^ ERROR invalid `sym` operand
34 changes: 19 additions & 15 deletions src/test/ui/asm/aarch64/type-check-2.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error: arguments for inline assembly must be copyable
--> $DIR/type-check-2.rs:48:31
--> $DIR/type-check-2.rs:46:31
|
LL | asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `SimdNonCopy` does not implement the Copy trait

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

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

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

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

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

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

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

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

error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/type-check-2.rs:19:28
Expand Down
9 changes: 8 additions & 1 deletion src/test/ui/asm/type-check-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ignore-spirv
// ignore-wasm32

#![feature(asm_const)]
#![feature(asm_const, asm_sym)]

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

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

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

Expand All @@ -59,6 +61,11 @@ fn main() {
}
}

unsafe fn generic<T>() {
asm!("{}", sym generic::<T>);
//~^ generic parameters may not be used in const operations
}

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

global_asm!("{}", const 0);
Expand Down
29 changes: 23 additions & 6 deletions src/test/ui/asm/type-check-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,31 @@ LL | let x = 0;
LL | asm!("{}", const const_bar(x));
| ^ non-constant value

error: invalid `sym` operand
--> $DIR/type-check-1.rs:47:24
|
LL | asm!("{}", sym x);
| ^ is a local variable
|
= help: `sym` operands must refer to either a function or a static

error: generic parameters may not be used in const operations
--> $DIR/type-check-1.rs:65:30
|
LL | asm!("{}", sym generic::<T>);
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:53:26
--> $DIR/type-check-1.rs:55:26
|
LL | asm!("{}", const 0f32);
| ^^^^ expected integer, found `f32`

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

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

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

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

error: aborting due to 13 previous errors
error: aborting due to 15 previous errors

Some errors have detailed explanations: E0277, E0308, E0435.
For more information about an error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/asm/x86_64/parse-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
asm!("{}", in(reg) foo => bar);
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
asm!("{}", sym foo + bar);
//~^ ERROR argument to `sym` must be a path expression
//~^ ERROR expected a path for argument to `sym`
asm!("", options(foo));
//~^ ERROR expected one of
asm!("", options(nomem foo));
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/asm/x86_64/parse-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
LL | asm!("{}", in(reg) foo => bar);
| ^^ expected one of 7 possible tokens

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

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

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

error: asm template must be a string literal
--> $DIR/parse-error.rs:134:13
Expand Down
15 changes: 11 additions & 4 deletions src/test/ui/asm/x86_64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

#[repr(simd)]
struct SimdNonCopy(f32, f32, f32, f32);
Expand Down Expand Up @@ -35,9 +35,7 @@ fn main() {
asm!("{}", sym S);
asm!("{}", sym main);
asm!("{}", sym C);
//~^ ERROR asm `sym` operand must point to a fn or static
asm!("{}", sym x);
//~^ ERROR asm `sym` operand must point to a fn or static
//~^ ERROR invalid `sym` operand

// Register operands must be Copy

Expand Down Expand Up @@ -80,3 +78,12 @@ fn main() {
asm!("{}", in(reg) u);
}
}

// Sym operands must point to a function or static

const C: i32 = 0;
static S: i32 = 0;
global_asm!("{}", sym S);
global_asm!("{}", sym main);
global_asm!("{}", sym C);
//~^ ERROR invalid `sym` operand
Loading

0 comments on commit e0ed0f4

Please sign in to comment.