Skip to content

Commit

Permalink
Unrolled build for rust-lang#132516
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#132516 - taiki-e:asm-ui, r=workingjubilee

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

rust-lang#131341 (comment)

> Btw, such unsupported registers are present in most architectures, but only aarch64/arm64ec, x86_64, and not yet merged [sparc/sparc64](https://github.com/rust-lang/rust/pull/132472/files#diff-02aebda3376c2b020265137f9ce2c387669ca5cfecd7d60494275c2387db5114) (and powerpc/powerpc64 by this PR) currently have ui tests for them.  I plan to add tests for other arches later.

Starting with RISC-V and s390x, which I'm familiar with and relatively easy to check for correctness.

(Relevant rustc code are supported_types/def_regs/overlapping_regs in [compiler/rustc_target/src/asm/riscv.rs](https://github.com/rust-lang/rust/blob/588a4203508ed7c76750c96b482641261630ed36/compiler/rustc_target/src/asm/riscv.rs) and [compiler/rustc_target/src/asm/s390x.rs](https://github.com/rust-lang/rust/blob/588a4203508ed7c76750c96b482641261630ed36/compiler/rustc_target/src/asm/s390x.rs).)

r? workingjubilee

`@rustbot` label +A-inline-assembly
  • Loading branch information
rust-timer authored Nov 4, 2024
2 parents 42188c3 + b07232d commit 3e5d2a7
Show file tree
Hide file tree
Showing 14 changed files with 1,387 additions and 50 deletions.
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.
//! - Be careful 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
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:34: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:36: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:38: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:40: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:42: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:44: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:46: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:97: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:100: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:103: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:106:26
|
LL | asm!("/* {} */", out(vreg) _);
| ^^^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: type `i32` cannot be used with this register class
--> $DIR/bad-reg.rs:97: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:100: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:103: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:34: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:36: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:38: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:40: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:42: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:44: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:46: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:97: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:100: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:103: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:106:26
|
LL | asm!("/* {} */", out(vreg) _);
| ^^^^^^^^^^^

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

error: aborting due to 14 previous errors

Loading

0 comments on commit 3e5d2a7

Please sign in to comment.