2024-02-16 20:02:50 +00:00
|
|
|
//@ only-x86_64
|
2024-05-01 16:54:20 -07:00
|
|
|
// Set the base cpu explicitly, in case the default has been changed.
|
2024-05-01 15:25:26 -07:00
|
|
|
//@ compile-flags: -C target-cpu=x86-64
|
2020-05-01 15:32:28 +02:00
|
|
|
|
|
|
|
|
#[target_feature(enable = "sse2")]
|
|
|
|
|
const fn sse2() {}
|
|
|
|
|
|
2023-11-26 19:55:01 +01:00
|
|
|
#[target_feature(enable = "sse2")]
|
|
|
|
|
#[target_feature(enable = "fxsr")]
|
|
|
|
|
const fn sse2_and_fxsr() {}
|
|
|
|
|
|
2020-05-01 15:32:28 +02:00
|
|
|
#[target_feature(enable = "avx")]
|
|
|
|
|
#[target_feature(enable = "bmi2")]
|
|
|
|
|
fn avx_bmi2() {}
|
|
|
|
|
|
|
|
|
|
struct Quux;
|
|
|
|
|
|
|
|
|
|
impl Quux {
|
|
|
|
|
#[target_feature(enable = "avx")]
|
|
|
|
|
#[target_feature(enable = "bmi2")]
|
|
|
|
|
fn avx_bmi2(&self) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn foo() {
|
2022-04-26 10:43:00 +00:00
|
|
|
sse2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `sse2` with `#[target_feature]` is unsafe
|
2022-04-26 10:43:00 +00:00
|
|
|
avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `avx_bmi2` with `#[target_feature]` is unsafe
|
2022-04-26 10:43:00 +00:00
|
|
|
Quux.avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe
|
2020-05-01 15:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[target_feature(enable = "sse2")]
|
|
|
|
|
fn bar() {
|
2024-07-26 10:04:27 -04:00
|
|
|
sse2();
|
2022-04-26 10:43:00 +00:00
|
|
|
avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `avx_bmi2` with `#[target_feature]` is unsafe
|
2022-04-26 10:43:00 +00:00
|
|
|
Quux.avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe
|
2020-05-01 15:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[target_feature(enable = "avx")]
|
|
|
|
|
fn baz() {
|
2022-04-26 10:43:00 +00:00
|
|
|
sse2();
|
|
|
|
|
avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `avx_bmi2` with `#[target_feature]` is unsafe
|
2022-04-26 10:43:00 +00:00
|
|
|
Quux.avx_bmi2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe
|
2020-05-01 15:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[target_feature(enable = "avx")]
|
|
|
|
|
#[target_feature(enable = "bmi2")]
|
|
|
|
|
fn qux() {
|
2022-04-26 10:43:00 +00:00
|
|
|
sse2();
|
2024-07-26 10:04:27 -04:00
|
|
|
avx_bmi2();
|
|
|
|
|
Quux.avx_bmi2();
|
2020-05-01 15:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-26 19:55:01 +01:00
|
|
|
const _: () = sse2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `sse2` with `#[target_feature]` is unsafe
|
2020-05-01 15:32:28 +02:00
|
|
|
|
2023-11-26 19:55:01 +01:00
|
|
|
const _: () = sse2_and_fxsr();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `sse2_and_fxsr` with `#[target_feature]` is unsafe
|
2023-11-26 19:55:01 +01:00
|
|
|
|
2023-11-28 20:37:02 +01:00
|
|
|
#[deny(unsafe_op_in_unsafe_fn)]
|
|
|
|
|
unsafe fn needs_unsafe_block() {
|
|
|
|
|
sse2();
|
2023-12-07 11:56:48 +00:00
|
|
|
//~^ ERROR call to function `sse2` with `#[target_feature]` is unsafe
|
2023-11-28 20:37:02 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-01 15:32:28 +02:00
|
|
|
fn main() {}
|