Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4d74712
Tweak type inference for `const` operands in inline asm
Amanieu May 25, 2024
575fc72
Work around #96304 by ignoring one test case
Amanieu Jun 11, 2024
97738e1
apply fix suggested by lcnr
folkertdev Jul 21, 2024
c77b569
Apply suggestions from code review
folkertdev Jul 22, 2024
d4ca1ac
rustfmt
Amanieu Jul 23, 2024
be66415
use `ErrorGuaranteed` from emit
folkertdev Jul 25, 2024
794434e
initial implementation of rustdoc nested aux-build
EtomicBomb Jul 24, 2024
d8211de
ordering and wrapping cross-crate-info tests
EtomicBomb Jul 24, 2024
f6f0ef4
reformatted rustdoc/cross-crate-info, fixing trailing newline issue
EtomicBomb Jul 24, 2024
12d87ee
file_stem and comment per notriddle
EtomicBomb Jul 25, 2024
f91da72
merge conflicts; fix rebase duplicating imports
EtomicBomb Jul 29, 2024
bd23e0e
canonicalize path in another place to fix #128411
EtomicBomb Jul 31, 2024
281c2fd
Inline and remove `parse_local_mk`.
nnethercote Jul 31, 2024
fe647f0
Remove `LhsExpr`.
nnethercote Jul 31, 2024
2eb2ef1
Streamline attribute stitching on AST nodes.
nnethercote Jul 31, 2024
9d77d17
Move a comment to a better spot.
nnethercote Aug 1, 2024
d1f05fd
Distinguish the two kinds of token range.
nnethercote Jul 31, 2024
b73077e
separate test file for invalid sym operand
folkertdev Aug 1, 2024
47e6db5
separate test file for invalid const operand
folkertdev Aug 1, 2024
6ba240a
Promote riscv64gc-unknown-linux-musl to tier 2
Amanieu Feb 26, 2024
b056ab6
Make riscv64gc-unknown-linux-musl dynamically linked by default
Amanieu Jun 22, 2024
beacd70
Add platform support document for riscv64gc-unknown-linux-musl
Amanieu Jun 22, 2024
41b017e
Add the `sha512`, `sm3` and `sm4` target features
sayantn Aug 1, 2024
2f0aaaf
std: Remove has_cpuid
workingjubilee Aug 2, 2024
36527d6
rustfmt: Remove `has_cpuid` from test
workingjubilee Aug 2, 2024
ea5cb4e
Rollup merge of #122049 - Amanieu:riscv64-musl-tier2, r=Mark-Simulacrum
matthiaskrgr Aug 2, 2024
5787038
Rollup merge of #125558 - Amanieu:const-asm-type, r=lcnr
matthiaskrgr Aug 2, 2024
ddac035
Rollup merge of #126704 - sayantn:sha, r=Amanieu
matthiaskrgr Aug 2, 2024
fbcd997
Rollup merge of #128161 - EtomicBomb:just-compiletest, r=notriddle
matthiaskrgr Aug 2, 2024
6f0816a
Rollup merge of #128483 - nnethercote:still-more-cfg-cleanups, r=petr…
matthiaskrgr Aug 2, 2024
c6e838e
Rollup merge of #128528 - workingjubilee:you-dont-need-to-see-this-cp…
matthiaskrgr Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
separate test file for invalid const operand
  • Loading branch information
folkertdev authored and Amanieu committed Aug 1, 2024
commit 47e6db542e4a80b6c4b3aa4ab2eb2a991474f24f
51 changes: 51 additions & 0 deletions tests/ui/asm/invalid-const-operand.rs
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
}
}
86 changes: 86 additions & 0 deletions tests/ui/asm/invalid-const-operand.stderr
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`.
18 changes: 9 additions & 9 deletions tests/ui/asm/invalid-sym-operand.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
14 changes: 7 additions & 7 deletions tests/ui/asm/invalid-sym-operand.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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
|
= help: `sym` operands must refer to either a function or a static

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

Expand Down
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`.