summaryrefslogtreecommitdiffstats
path: root/tests/ui/asm/x86_64/const.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/x86_64/const.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/x86_64/const.rs')
-rw-r--r--tests/ui/asm/x86_64/const.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/asm/x86_64/const.rs b/tests/ui/asm/x86_64/const.rs
new file mode 100644
index 000000000..d523ae021
--- /dev/null
+++ b/tests/ui/asm/x86_64/const.rs
@@ -0,0 +1,44 @@
+// only-x86_64
+// run-pass
+// needs-asm-support
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+#![feature(asm_const)]
+
+use std::arch::{asm, global_asm};
+
+fn const_generic<const X: usize>() -> usize {
+ unsafe {
+ let a: usize;
+ asm!("mov {}, {}", out(reg) a, const X);
+ a
+ }
+}
+
+const fn constfn(x: usize) -> usize {
+ x
+}
+
+fn main() {
+ unsafe {
+ let a: usize;
+ asm!("mov {}, {}", out(reg) a, const 5);
+ assert_eq!(a, 5);
+
+ let b: usize;
+ asm!("mov {}, {}", out(reg) b, const constfn(5));
+ assert_eq!(b, 5);
+
+ let c: usize;
+ asm!("mov {}, {}", out(reg) c, const constfn(5) + constfn(5));
+ assert_eq!(c, 10);
+ }
+
+ let d = const_generic::<5>();
+ assert_eq!(d, 5);
+}
+
+global_asm!("mov eax, {}", const 5);
+global_asm!("mov eax, {}", const constfn(5));
+global_asm!("mov eax, {}", const constfn(5) + constfn(5));