Skip to content

Commit

Permalink
separate test file for invalid sym operand
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev authored and Amanieu committed Aug 1, 2024
1 parent be66415 commit b73077e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 116 deletions.
18 changes: 0 additions & 18 deletions tests/ui/asm/aarch64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ fn main() {
unsafe {
// Inputs must be initialized

// Sym operands must point to a function or static

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

// Register operands must be Copy

asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
Expand Down Expand Up @@ -65,12 +56,3 @@ 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: 9 additions & 25 deletions tests/ui/asm/aarch64/type-check-2.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
error: invalid `sym` operand
--> $DIR/type-check-2.rs:75:19
|
LL | global_asm!("{}", sym C);
| ^^^^^ is an `i32`
|
= help: `sym` operands must refer to either a function or a static

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

error: arguments for inline assembly must be copyable
--> $DIR/type-check-2.rs:29:31
--> $DIR/type-check-2.rs:20: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:41:28: 41:36}` for inline assembly
--> $DIR/type-check-2.rs:41:28
error: cannot use value of type `{closure@$DIR/type-check-2.rs:32:28: 32:36}` for inline assembly
--> $DIR/type-check-2.rs:32: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:43:28
--> $DIR/type-check-2.rs:34:28
|
LL | asm!("{}", in(reg) vec![0]);
| ^^^^^^^
Expand All @@ -40,36 +24,36 @@ 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:45:28
--> $DIR/type-check-2.rs:36: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:47:28
--> $DIR/type-check-2.rs:38: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:55:31
--> $DIR/type-check-2.rs:46: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:58:31
--> $DIR/type-check-2.rs:49: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: aborting due to 9 previous errors
error: aborting due to 7 previous errors

30 changes: 30 additions & 0 deletions tests/ui/asm/invalid-sym-operand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::arch::{asm, global_asm};

fn main() {
unsafe {
// Sym operands must point to a function or static

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

unsafe fn generic<T>() {
asm!("{}", sym generic::<T>);
}

// 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
26 changes: 26 additions & 0 deletions tests/ui/asm/invalid-sym-operand.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: invalid `sym` operand
--> $DIR/invalid-sym-operand.rs:14:24
|
LL | asm!("{}", sym x);
| ^ is a local variable
|
= help: `sym` operands must refer to either a function or a static

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

error: invalid `sym` operand
--> $DIR/invalid-sym-operand.rs:29:19
|
LL | global_asm!("{}", sym C);
| ^^^^^ is an `i32`
|
= help: `sym` operands must refer to either a function or a static

error: aborting due to 3 previous errors

6 changes: 0 additions & 6 deletions tests/ui/asm/type-check-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ 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 @@ -64,10 +62,6 @@ fn main() {
}
}

unsafe fn generic<T>() {
asm!("{}", sym generic::<T>);
}

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

global_asm!("{}", const 0);
Expand Down
20 changes: 6 additions & 14 deletions tests/ui/asm/type-check-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ help: consider using `const` instead of `let`
LL | const x: /* Type */ = 0;
| ~~~~~ ++++++++++++

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

error: invalid asm output
--> $DIR/type-check-1.rs:14:29
|
Expand Down Expand Up @@ -103,7 +95,7 @@ LL | asm!("{}", inout(reg) v[..]);
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:57:20
--> $DIR/type-check-1.rs:55:20
|
LL | asm!("{}", const 0f32);
| ^^^^^^----
Expand All @@ -113,7 +105,7 @@ LL | asm!("{}", const 0f32);
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:59:20
--> $DIR/type-check-1.rs:57:20
|
LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^------------
Expand All @@ -123,7 +115,7 @@ LL | asm!("{}", const 0 as *mut u8);
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:62:20
--> $DIR/type-check-1.rs:60:20
|
LL | asm!("{}", const &0);
| ^^^^^^--
Expand All @@ -133,7 +125,7 @@ LL | asm!("{}", const &0);
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:76:19
--> $DIR/type-check-1.rs:70:19
|
LL | global_asm!("{}", const 0f32);
| ^^^^^^----
Expand All @@ -143,7 +135,7 @@ LL | global_asm!("{}", const 0f32);
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:78:19
--> $DIR/type-check-1.rs:72:19
|
LL | global_asm!("{}", const 0 as *mut u8);
| ^^^^^^------------
Expand All @@ -152,7 +144,7 @@ LL | global_asm!("{}", const 0 as *mut u8);
|
= help: `const` operands must be of an integer type

error: aborting due to 17 previous errors
error: aborting due to 16 previous errors

Some errors have detailed explanations: E0277, E0435.
For more information about an error, try `rustc --explain E0277`.
20 changes: 0 additions & 20 deletions tests/ui/asm/x86_64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ fn main() {
asm!("{}", out(reg) v[0]);
asm!("{}", inout(reg) v[0]);

// Sym operands must point to a function or static

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

// Register operands must be Copy

asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
Expand Down Expand Up @@ -79,12 +68,3 @@ 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
42 changes: 9 additions & 33 deletions tests/ui/asm/x86_64/type-check-2.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
error: invalid `sym` operand
--> $DIR/type-check-2.rs:38:24
|
LL | asm!("{}", sym x);
| ^ is a local variable
|
= help: `sym` operands must refer to either a function or a static

error: arguments for inline assembly must be copyable
--> $DIR/type-check-2.rs:43:32
--> $DIR/type-check-2.rs:32:32
|
LL | asm!("{}", in(xmm_reg) 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:55:28: 55:36}` for inline assembly
--> $DIR/type-check-2.rs:55:28
error: cannot use value of type `{closure@$DIR/type-check-2.rs:44:28: 44:36}` for inline assembly
--> $DIR/type-check-2.rs:44: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:57:28
--> $DIR/type-check-2.rs:46:28
|
LL | asm!("{}", in(reg) vec![0]);
| ^^^^^^^
Expand All @@ -32,45 +24,37 @@ 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:59:28
--> $DIR/type-check-2.rs:48: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:61:28
--> $DIR/type-check-2.rs:50: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:69:31
--> $DIR/type-check-2.rs:58: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:72:31
--> $DIR/type-check-2.rs:61: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: invalid `sym` operand
--> $DIR/type-check-2.rs:36:20
|
LL | asm!("{}", sym C);
| ^^^^^ is an `i32`
|
= help: `sym` operands must refer to either a function or a static

error[E0381]: used binding `x` isn't initialized
--> $DIR/type-check-2.rs:15:28
|
Expand Down Expand Up @@ -113,15 +97,7 @@ help: consider changing this to be mutable
LL | let mut v: Vec<u64> = vec![0, 1, 2];
| +++

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

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

Some errors have detailed explanations: E0381, E0596.
For more information about an error, try `rustc --explain E0381`.

0 comments on commit b73077e

Please sign in to comment.