Skip to content

Commit

Permalink
separate test file for invalid const operand
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 1, 2024
1 parent 74f711e commit 08c8887
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 127 deletions.
33 changes: 33 additions & 0 deletions tests/ui/asm/invalid-const-operand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv

#![feature(asm_const)]

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

fn main() {
unsafe {
// Const operands must be integers and must be constants.

asm!("{}", const 0);
asm!("{}", const 0i32);
asm!("{}", const 0i128);
asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
asm!("{}", const &0);
//~^ ERROR invalid type for `const` operand
}
}

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

global_asm!("{}", const 0);
global_asm!("{}", const 0i32);
global_asm!("{}", const 0i128);
global_asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
global_asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
52 changes: 52 additions & 0 deletions tests/ui/asm/invalid-const-operand.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:16:20
|
LL | asm!("{}", const 0f32);
| ^^^^^^----
| |
| is an `f32`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:18:20
|
LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^------------
| |
| is a `*mut u8`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:20:20
|
LL | asm!("{}", const &0);
| ^^^^^^--
| |
| is a `&i32`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:30:19
|
LL | global_asm!("{}", const 0f32);
| ^^^^^^----
| |
| is an `f32`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:32:19
|
LL | global_asm!("{}", const 0 as *mut u8);
| ^^^^^^------------
| |
| is a `*mut u8`
|
= help: `const` operands must be of an integer type

error: aborting due to 5 previous errors

41 changes: 0 additions & 41 deletions tests/ui/asm/type-check-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,5 @@ fn main() {
asm!("{}", inout(reg) v[..]);
//~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
//~| ERROR cannot use value of type `[u64]` for inline assembly

// Constants must be... constant

let x = 0;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
asm!("{}", const x);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_foo(0));
asm!("{}", const const_foo(x));
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_bar(0));
asm!("{}", const const_bar(x));
//~^ ERROR attempt to use a non-constant value in a constant

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

asm!("{}", const 0);
asm!("{}", const 0i32);
asm!("{}", const 0i128);
asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand

asm!("{}", const &0);
//~^ ERROR invalid type for `const` operand
}
}

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

global_asm!("{}", const 0);
global_asm!("{}", const 0i32);
global_asm!("{}", const 0i128);
global_asm!("{}", const 0f32);
//~^ ERROR invalid type for `const` operand
global_asm!("{}", const 0 as *mut u8);
//~^ ERROR invalid type for `const` operand
88 changes: 2 additions & 86 deletions tests/ui/asm/type-check-1.stderr
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:41:26
|
LL | asm!("{}", const x);
| ^ non-constant value
|
help: consider using `const` instead of `let`
|
LL | const x: /* Type */ = 0;
| ~~~~~ ++++++++++++

error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:44:36
|
LL | asm!("{}", const const_foo(x));
| ^ non-constant value
|
help: consider using `const` instead of `let`
|
LL | const x: /* Type */ = 0;
| ~~~~~ ++++++++++++

error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:47:36
|
LL | asm!("{}", const const_bar(x));
| ^ non-constant value
|
help: consider using `const` instead of `let`
|
LL | const x: /* Type */ = 0;
| ~~~~~ ++++++++++++

error: invalid asm output
--> $DIR/type-check-1.rs:14:29
|
Expand Down Expand Up @@ -94,57 +61,6 @@ 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:55:20
|
LL | asm!("{}", const 0f32);
| ^^^^^^----
| |
| is an `f32`
|
= help: `const` operands must be of an integer type

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

error: invalid type for `const` operand
--> $DIR/type-check-1.rs:60:20
|
LL | asm!("{}", const &0);
| ^^^^^^--
| |
| is a `&i32`
|
= help: `const` operands must be of an integer type

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

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

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

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

0 comments on commit 08c8887

Please sign in to comment.