separate test file for invalid const operand

This commit is contained in:
Folkert 2024-08-01 18:57:59 +02:00 committed by Amanieu d'Antras
parent b73077e3d8
commit 47e6db542e
6 changed files with 158 additions and 146 deletions

View File

@ -0,0 +1,51 @@
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv
#![feature(asm_const)]
use std::arch::{asm, global_asm};
// 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
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
// 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
}
}

View File

@ -0,0 +1,86 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/invalid-const-operand.rs:42: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/invalid-const-operand.rs:45: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/invalid-const-operand.rs:48:36
|
LL | asm!("{}", const const_bar(x));
| ^ non-constant value
|
help: consider using `const` instead of `let`
|
LL | const x: /* Type */ = 0;
| ~~~~~ ++++++++++++
error: invalid type for `const` operand
--> $DIR/invalid-const-operand.rs:14: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:16:19
|
LL | global_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:26: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:28: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:30:20
|
LL | asm!("{}", const &0);
| ^^^^^^--
| |
| is a `&i32`
|
= help: `const` operands must be of an integer type
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0435`.

View File

@ -1,5 +1,14 @@
use std::arch::{asm, global_asm};
// 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
fn main() {
unsafe {
// Sym operands must point to a function or static
@ -19,12 +28,3 @@ fn main() {
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

View File

@ -1,5 +1,5 @@
error: invalid `sym` operand
--> $DIR/invalid-sym-operand.rs:14:24
--> $DIR/invalid-sym-operand.rs:23:24
|
LL | asm!("{}", sym x);
| ^ is a local variable
@ -7,20 +7,20 @@ LL | asm!("{}", sym x);
= 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
--> $DIR/invalid-sym-operand.rs:9: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/invalid-sym-operand.rs:21:20
|
LL | 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

View File

@ -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

View File

@ -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
|
@ -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: aborting due to 8 previous errors
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
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`.