summaryrefslogtreecommitdiffstats
path: root/tests/assembly/target-feature-multiple.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/assembly/target-feature-multiple.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/assembly/target-feature-multiple.rs')
-rw-r--r--tests/assembly/target-feature-multiple.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/assembly/target-feature-multiple.rs b/tests/assembly/target-feature-multiple.rs
new file mode 100644
index 000000000..5c5d93863
--- /dev/null
+++ b/tests/assembly/target-feature-multiple.rs
@@ -0,0 +1,42 @@
+// assembly-output: emit-asm
+// needs-llvm-components: x86
+// revisions: TWOFLAGS SINGLEFLAG
+// compile-flags: --target=x86_64-unknown-linux-gnu
+// [TWOFLAGS] compile-flags: -C target-feature=+rdrnd -C target-feature=+rdseed
+// [SINGLEFLAG] compile-flags: -C target-feature=+rdrnd,+rdseed
+
+// Target features set via flags aren't necessarily reflected in the IR, so the only way to test
+// them is to build code that requires the features to be enabled to work.
+//
+// In this particular test if `rdrnd,rdseed` somehow didn't make it to LLVM, the instruction
+// selection should crash.
+//
+// > LLVM ERROR: Cannot select: 0x7f00f400c010: i32,i32,ch = X86ISD::RDSEED 0x7f00f400bfa8:2
+// > In function: foo
+//
+// See also tests/codegen/target-feature-overrides.rs
+#![feature(no_core, lang_items, link_llvm_intrinsics, abi_unadjusted)]
+#![crate_type = "lib"]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+#[lang = "copy"]
+trait Copy {}
+impl Copy for u32 {}
+
+// Use of these requires target features to be enabled
+extern "unadjusted" {
+ #[link_name = "llvm.x86.rdrand.32"]
+ fn x86_rdrand32_step() -> (u32, i32);
+ #[link_name = "llvm.x86.rdseed.32"]
+ fn x86_rdseed32_step() -> (u32, i32);
+}
+
+#[no_mangle]
+pub unsafe fn foo() -> (u32, u32) {
+ // CHECK-LABEL: foo:
+ // CHECK: rdrand
+ // CHECK: rdseed
+ (x86_rdrand32_step().0, x86_rdseed32_step().0)
+}