about summary refs log tree commit diff
path: root/tests/ui/target-feature/no-llvm-leaks.rs
blob: 50544b97a96dc2ed20d67f1c3f9d01d59983dfe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//@ add-core-stubs
//@ revisions: aarch64 x86-64
//@ [aarch64] compile-flags: -Ctarget-feature=+neon,+fp16,+fhm --target=aarch64-unknown-linux-gnu
//@ [aarch64] needs-llvm-components: aarch64
//@ [x86-64] compile-flags: -Ctarget-feature=+sse4.2,+rdrand --target=x86_64-unknown-linux-gnu
//@ [x86-64] needs-llvm-components: x86
//@ build-pass
#![no_core]
#![crate_type = "rlib"]
#![feature(intrinsics, rustc_attrs, no_core, lang_items, staged_api)]
#![stable(feature = "test", since = "1.0.0")]

extern crate minicore;
use minicore::*;

#[stable(feature = "test", since = "1.0.0")]
#[rustc_const_stable(feature = "test", since = "1.0.0")]
#[rustc_intrinsic]
const unsafe fn unreachable() -> !;

#[rustc_builtin_macro]
macro_rules! cfg {
    ($($cfg:tt)*) => {};
}

// Test code
const fn do_or_die(cond: bool) {
    if cond {
    } else {
        unsafe { unreachable() }
    }
}

macro_rules! assert {
    ($x:expr $(,)?) => {
        const _: () = do_or_die($x);
    };
}


#[cfg(target_arch = "aarch64")]
fn check_aarch64() {
    // These checks that the rustc feature name is used, not the LLVM feature.

    assert!(cfg!(target_feature = "neon"));
    // #[expect(unexpected_cfgs)] except that 32-bit arm actually use fp-armv8
    { assert!(cfg!(not(target_feature = "fp-armv8"))); }

    assert!(cfg!(target_feature = "fhm"));
    #[expect(unexpected_cfgs)]
    { assert!(cfg!(not(target_feature = "fp16fml"))); }

    assert!(cfg!(target_feature = "fp16"));
    #[expect(unexpected_cfgs)]
    { assert!(cfg!(not(target_feature = "fullfp16"))); }
}

#[cfg(target_arch = "x86_64")]
fn check_x86_64() {
    // This checks that the rustc feature name is used, not the LLVM feature.
    assert!(cfg!(target_feature = "rdrand"));
    #[expect(unexpected_cfgs)]
    { assert!(cfg!(not(target_feature = "rdrnd"))); }

    // Likewise: We enable LLVM's crc32 feature with SSE4.2, but Rust says it's just SSE4.2
    assert!(cfg!(target_feature = "sse4.2"));
    #[expect(unexpected_cfgs)]
    { assert!(cfg!(not(target_feature = "crc32"))); }
}