Skip to content

Add bad-reg inline assembly ui test for RISC-V and s390x #132516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
13 changes: 11 additions & 2 deletions tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
//!
//! - `minicore` is **only** intended for `core` items, and the stubs should match the actual `core`
//! items.
//! - Becareful of adding new features and things that are only available for a subset of targets.
//!
//! # References
//!
//! This is partially adapted from `rustc_codegen_cranelift`:
//! <https://github.com/rust-lang/rust/blob/c0b5cc9003f6464c11ae1c0662c6a7e06f6f5cab/compiler/rustc_codegen_cranelift/example/mini_core.rs>.
// ignore-tidy-linelength

#![feature(no_core, lang_items, rustc_attrs)]
#![feature(no_core, lang_items, rustc_attrs, decl_macro)]
#![allow(unused, improper_ctypes_definitions, internal_features)]
#![feature(asm_experimental_arch)]
#![no_std]
#![no_core]

Expand All @@ -37,7 +39,9 @@ impl<T: ?Sized> LegacyReceiver for &mut T {}
#[lang = "copy"]
pub trait Copy: Sized {}

impl_marker_trait!(Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64 ]);
impl_marker_trait!(
Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64, f32, f64 ]
);
impl<'a, T: ?Sized> Copy for &'a T {}
impl<T: ?Sized> Copy for *const T {}
impl<T: ?Sized> Copy for *mut T {}
Expand Down Expand Up @@ -70,3 +74,8 @@ impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {}
pub struct UnsafeCell<T: ?Sized> {
value: T,
}

#[rustc_builtin_macro]
pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
/* compiler built-in */
}
212 changes: 212 additions & 0 deletions tests/ui/asm/riscv/bad-reg.riscv32e.stderr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a similar test for rv32e, actually: https://github.com/rust-lang/rust/blob/b3f75cc872cfd306860c3ad76a239e719015f855/tests/ui/abi/riscv32e-registers.rs

I suppose we should merge them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both should be placed in ui/asm/riscv, but I don't think they can be merged since they test checks that are performed at different stages.

  • riscv32e-registers.rs is to see if the LLVM's assembler can reject the use of unsupported registers in assembly code (i.e., invalid assembly code).
  • bad-reg.rs is to see if the rustc can reject the use of unsupported registers in the asm! API (in,out,inout,etc.).

Only code that passes the latter check is passed to LLVM, so it is probably difficult to test that both work in a single test file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved tests/ui/abi/riscv32e-registers.rs to tests/ui/asm/riscv and added comments explaining the difference to bad-reg.rs. (b07232d)

Copy link
Member

@workingjubilee workingjubilee Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. That makes sense, thank you! I wasn't entirely sure of which things were checked where.

Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
error: invalid register `s1`: s1 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("s1") _);
| ^^^^^^^^^^^

error: invalid register `fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("fp") _);
| ^^^^^^^^^^^

error: invalid register `sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("sp") _);
| ^^^^^^^^^^^

error: invalid register `gp`: the global pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("gp") _);
| ^^^^^^^^^^^

error: invalid register `gp`: the global pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:39:18
|
LL | asm!("", out("gp") _);
| ^^^^^^^^^^^

error: invalid register `tp`: the thread pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:41:18
|
LL | asm!("", out("tp") _);
| ^^^^^^^^^^^

error: invalid register `zero`: the zero register cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:43:18
|
LL | asm!("", out("zero") _);
| ^^^^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:94:18
|
LL | asm!("", in("v0") x);
| ^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:97:18
|
LL | asm!("", out("v0") x);
| ^^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:100:26
|
LL | asm!("/* {} */", in(vreg) x);
| ^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:103:26
|
LL | asm!("/* {} */", out(vreg) _);
| ^^^^^^^^^^^

error: cannot use register `x16`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:46:18
|
LL | asm!("", out("x16") _);
| ^^^^^^^^^^^^

error: cannot use register `x17`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:48:18
|
LL | asm!("", out("x17") _);
| ^^^^^^^^^^^^

error: cannot use register `x18`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:50:18
|
LL | asm!("", out("x18") _);
| ^^^^^^^^^^^^

error: cannot use register `x19`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:52:18
|
LL | asm!("", out("x19") _);
| ^^^^^^^^^^^^

error: cannot use register `x20`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:54:18
|
LL | asm!("", out("x20") _);
| ^^^^^^^^^^^^

error: cannot use register `x21`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:56:18
|
LL | asm!("", out("x21") _);
| ^^^^^^^^^^^^

error: cannot use register `x22`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:58:18
|
LL | asm!("", out("x22") _);
| ^^^^^^^^^^^^

error: cannot use register `x23`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:60:18
|
LL | asm!("", out("x23") _);
| ^^^^^^^^^^^^

error: cannot use register `x24`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:62:18
|
LL | asm!("", out("x24") _);
| ^^^^^^^^^^^^

error: cannot use register `x25`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:64:18
|
LL | asm!("", out("x25") _);
| ^^^^^^^^^^^^

error: cannot use register `x26`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:66:18
|
LL | asm!("", out("x26") _);
| ^^^^^^^^^^^^

error: cannot use register `x27`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:68:18
|
LL | asm!("", out("x27") _);
| ^^^^^^^^^^^^

error: cannot use register `x28`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:70:18
|
LL | asm!("", out("x28") _);
| ^^^^^^^^^^^^

error: cannot use register `x29`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:72:18
|
LL | asm!("", out("x29") _);
| ^^^^^^^^^^^^

error: cannot use register `x30`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:74:18
|
LL | asm!("", out("x30") _);
| ^^^^^^^^^^^^

error: cannot use register `x31`: register can't be used with the `e` target feature
--> $DIR/bad-reg.rs:76:18
|
LL | asm!("", out("x31") _);
| ^^^^^^^^^^^^

error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:80:26
|
LL | asm!("/* {} */", in(freg) f);
| ^^^^^^^^^^

error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:82:26
|
LL | asm!("/* {} */", out(freg) _);
| ^^^^^^^^^^^

error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:84:26
|
LL | asm!("/* {} */", in(freg) d);
| ^^^^^^^^^^

error: register class `freg` requires at least one of the following target features: d, f
--> $DIR/bad-reg.rs:87:26
|
LL | asm!("/* {} */", out(freg) d);
| ^^^^^^^^^^^

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:94:27
|
LL | asm!("", in("v0") x);
| ^
|
= note: register class `vreg` supports these types:

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:97:28
|
LL | asm!("", out("v0") x);
| ^
|
= note: register class `vreg` supports these types:

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:100:35
|
LL | asm!("/* {} */", in(vreg) x);
| ^
|
= note: register class `vreg` supports these types:

error: aborting due to 34 previous errors

92 changes: 92 additions & 0 deletions tests/ui/asm/riscv/bad-reg.riscv32gc.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
error: invalid register `s1`: s1 is used internally by LLVM and cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:31:18
|
LL | asm!("", out("s1") _);
| ^^^^^^^^^^^

error: invalid register `fp`: the frame pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:33:18
|
LL | asm!("", out("fp") _);
| ^^^^^^^^^^^

error: invalid register `sp`: the stack pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:35:18
|
LL | asm!("", out("sp") _);
| ^^^^^^^^^^^

error: invalid register `gp`: the global pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:37:18
|
LL | asm!("", out("gp") _);
| ^^^^^^^^^^^

error: invalid register `gp`: the global pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:39:18
|
LL | asm!("", out("gp") _);
| ^^^^^^^^^^^

error: invalid register `tp`: the thread pointer cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:41:18
|
LL | asm!("", out("tp") _);
| ^^^^^^^^^^^

error: invalid register `zero`: the zero register cannot be used as an operand for inline asm
--> $DIR/bad-reg.rs:43:18
|
LL | asm!("", out("zero") _);
| ^^^^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:94:18
|
LL | asm!("", in("v0") x);
| ^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:97:18
|
LL | asm!("", out("v0") x);
| ^^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:100:26
|
LL | asm!("/* {} */", in(vreg) x);
| ^^^^^^^^^^

error: register class `vreg` can only be used as a clobber, not as an input or output
--> $DIR/bad-reg.rs:103:26
|
LL | asm!("/* {} */", out(vreg) _);
| ^^^^^^^^^^^

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:94:27
|
LL | asm!("", in("v0") x);
| ^
|
= note: register class `vreg` supports these types:

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:97:28
|
LL | asm!("", out("v0") x);
| ^
|
= note: register class `vreg` supports these types:

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:100:35
|
LL | asm!("/* {} */", in(vreg) x);
| ^
|
= note: register class `vreg` supports these types:

error: aborting due to 14 previous errors

Loading
Loading