]> git.lizzy.rs Git - rust.git/blob - tests/assembly/target-feature-multiple.rs
Rollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot
[rust.git] / tests / assembly / target-feature-multiple.rs
1 // assembly-output: emit-asm
2 // needs-llvm-components: x86
3 // revisions: TWOFLAGS SINGLEFLAG
4 // compile-flags: --target=x86_64-unknown-linux-gnu
5 // [TWOFLAGS] compile-flags: -C target-feature=+rdrnd -C target-feature=+rdseed
6 // [SINGLEFLAG] compile-flags: -C target-feature=+rdrnd,+rdseed
7
8 // Target features set via flags aren't necessarily reflected in the IR, so the only way to test
9 // them is to build code that requires the features to be enabled to work.
10 //
11 // In this particular test if `rdrnd,rdseed` somehow didn't make it to LLVM, the instruction
12 // selection should crash.
13 //
14 // > LLVM ERROR: Cannot select: 0x7f00f400c010: i32,i32,ch = X86ISD::RDSEED 0x7f00f400bfa8:2
15 // > In function: foo
16 //
17 // See also tests/codegen/target-feature-overrides.rs
18 #![feature(no_core, lang_items, link_llvm_intrinsics, abi_unadjusted)]
19 #![crate_type = "lib"]
20 #![no_core]
21
22 #[lang = "sized"]
23 trait Sized {}
24 #[lang = "copy"]
25 trait Copy {}
26 impl Copy for u32 {}
27
28 // Use of these requires target features to be enabled
29 extern "unadjusted" {
30     #[link_name = "llvm.x86.rdrand.32"]
31     fn x86_rdrand32_step() -> (u32, i32);
32     #[link_name = "llvm.x86.rdseed.32"]
33     fn x86_rdseed32_step() -> (u32, i32);
34 }
35
36 #[no_mangle]
37 pub unsafe fn foo() -> (u32, u32) {
38     // CHECK-LABEL: foo:
39     // CHECK: rdrand
40     // CHECK: rdseed
41     (x86_rdrand32_step().0, x86_rdseed32_step().0)
42 }