]> git.proxmox.com Git - rustc.git/blob - tests/ui/target-feature/no-llvm-leaks.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / target-feature / no-llvm-leaks.rs
1 // revisions: aarch64 x86-64
2 // [aarch64] compile-flags: -Ctarget-feature=+neon,+fp16,+fhm --target=aarch64-unknown-linux-gnu
3 // [aarch64] needs-llvm-components: aarch64
4 // [x86-64] compile-flags: -Ctarget-feature=+sse4.2,+rdrand --target=x86_64-unknown-linux-gnu
5 // [x86-64] needs-llvm-components: x86
6 // build-pass
7 #![no_core]
8 #![crate_type = "rlib"]
9 #![feature(intrinsics, rustc_attrs, no_core, lang_items, staged_api)]
10 #![stable(feature = "test", since = "1.0.0")]
11
12 // Supporting minimal rust core code
13 #[lang = "sized"]
14 trait Sized {}
15 #[lang = "copy"]
16 trait Copy {}
17 impl Copy for bool {}
18
19 extern "rust-intrinsic" {
20 #[rustc_const_stable(feature = "test", since = "1.0.0")]
21 fn unreachable() -> !;
22 }
23
24 #[rustc_builtin_macro]
25 macro_rules! cfg {
26 ($($cfg:tt)*) => {};
27 }
28
29 // Test code
30 const fn do_or_die(cond: bool) {
31 if cond {
32 } else {
33 unsafe { unreachable() }
34 }
35 }
36
37 macro_rules! assert {
38 ($x:expr $(,)?) => {
39 const _: () = do_or_die($x);
40 };
41 }
42
43
44 #[cfg(target_arch = "aarch64")]
45 fn check_aarch64() {
46 // This checks that the rustc feature name is used, not the LLVM feature.
47 assert!(cfg!(target_feature = "neon"));
48 assert!(cfg!(not(target_feature = "fp-armv8")));
49 assert!(cfg!(target_feature = "fhm"));
50 assert!(cfg!(not(target_feature = "fp16fml")));
51 assert!(cfg!(target_feature = "fp16"));
52 assert!(cfg!(not(target_feature = "fullfp16")));
53 }
54
55 #[cfg(target_arch = "x86_64")]
56 fn check_x86_64() {
57 // This checks that the rustc feature name is used, not the LLVM feature.
58 assert!(cfg!(target_feature = "rdrand"));
59 assert!(cfg!(not(target_feature = "rdrnd")));
60
61 // Likewise: We enable LLVM's crc32 feature with SSE4.2, but Rust says it's just SSE4.2
62 assert!(cfg!(target_feature = "sse4.2"));
63 assert!(cfg!(not(target_feature = "crc32")));
64 }