summaryrefslogtreecommitdiffstats
path: root/tests/ui/asm/type-check-1.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/asm/type-check-1.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/asm/type-check-1.rs')
-rw-r--r--tests/ui/asm/type-check-1.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/ui/asm/type-check-1.rs b/tests/ui/asm/type-check-1.rs
new file mode 100644
index 000000000..59f7b36af
--- /dev/null
+++ b/tests/ui/asm/type-check-1.rs
@@ -0,0 +1,79 @@
+// needs-asm-support
+// ignore-nvptx64
+// ignore-spirv
+// ignore-wasm32
+
+#![feature(asm_const)]
+
+use std::arch::{asm, global_asm};
+
+fn main() {
+ unsafe {
+ // Outputs must be place expressions
+
+ asm!("{}", in(reg) 1 + 2);
+ asm!("{}", out(reg) 1 + 2);
+ //~^ ERROR invalid asm output
+ asm!("{}", inout(reg) 1 + 2);
+ //~^ ERROR invalid asm output
+
+ // Operands must be sized
+
+ let v: [u64; 3] = [0, 1, 2];
+ asm!("{}", in(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
+ asm!("{}", out(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
+ 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
+ asm!("{}", sym x);
+ //~^ ERROR invalid `sym` operand
+
+ // Const operands must be integers and must be constants.
+
+ asm!("{}", const 0);
+ asm!("{}", const 0i32);
+ asm!("{}", const 0i128);
+ asm!("{}", const 0f32);
+ //~^ ERROR mismatched types
+ asm!("{}", const 0 as *mut u8);
+ //~^ ERROR mismatched types
+ asm!("{}", const &0);
+ //~^ ERROR mismatched types
+ }
+}
+
+unsafe fn generic<T>() {
+ asm!("{}", sym generic::<T>);
+}
+
+// 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 mismatched types
+global_asm!("{}", const 0 as *mut u8);
+//~^ ERROR mismatched types