-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate test file for invalid const operand
- Loading branch information
1 parent
b73077e
commit 47e6db5
Showing
6 changed files
with
155 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters