]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add gimple test for black box intrinsic
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 17 Apr 2025 16:28:52 +0000 (18:28 +0200)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Thu, 17 Apr 2025 18:05:17 +0000 (18:05 +0000)
gcc/testsuite/ChangeLog:

* rust/compile/black_box.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/testsuite/rust/compile/black_box.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/compile/black_box.rs b/gcc/testsuite/rust/compile/black_box.rs
new file mode 100644 (file)
index 0000000..80615af
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-options "-fdump-tree-gimple" }
+#![feature(rustc_attrs)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[rustc_builtin_macro]
+macro_rules! llvm_asm {
+    () => {};
+}
+
+pub fn black_box<T>(mut dummy: T) -> T {
+    unsafe {
+        // { dg-final { scan-tree-dump-times {memory} 1 gimple } }
+        llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile");
+    }
+
+    dummy
+}
+
+fn my_function(a: i32) -> i32 {
+    a
+}
+
+fn main() {
+    let dummy: i32 = 42;
+    let _ = black_box(my_function(dummy));
+}