From: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
---
 gcc/testsuite/rust/compile/black_box.rs | 28 +++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/black_box.rs

diff --git a/gcc/testsuite/rust/compile/black_box.rs 
b/gcc/testsuite/rust/compile/black_box.rs
new file mode 100644
index 00000000000..80615af5b5d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/black_box.rs
@@ -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));
+}
-- 
2.49.0

Reply via email to