From 3e8ce42d42ce6c6fed3f3db7ee77591a87eddc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Sun, 16 Jul 2023 13:20:06 +0200 Subject: [PATCH] Add const-eval test for `#[target_feature(enable = ...)]` function calls --- .../const-eval/const_fn_target_feature.rs | 17 +++++++++++++++++ .../const-eval/const_fn_target_feature.stderr | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ui/consts/const-eval/const_fn_target_feature.rs create mode 100644 tests/ui/consts/const-eval/const_fn_target_feature.stderr diff --git a/tests/ui/consts/const-eval/const_fn_target_feature.rs b/tests/ui/consts/const-eval/const_fn_target_feature.rs new file mode 100644 index 00000000000..5d02ce3f21b --- /dev/null +++ b/tests/ui/consts/const-eval/const_fn_target_feature.rs @@ -0,0 +1,17 @@ +// only-x86_64 +// compile-flags:-C target-feature=+ssse3 + +#![crate_type = "lib"] + +// ok (ssse3 enabled at compile time) +const A: () = unsafe { ssse3_fn() }; + +// error (avx2 not enabled at compile time) +const B: () = unsafe { avx2_fn() }; +//~^ ERROR evaluation of constant value failed + +#[target_feature(enable = "ssse3")] +const unsafe fn ssse3_fn() {} + +#[target_feature(enable = "avx2")] +const unsafe fn avx2_fn() {} diff --git a/tests/ui/consts/const-eval/const_fn_target_feature.stderr b/tests/ui/consts/const-eval/const_fn_target_feature.stderr new file mode 100644 index 00000000000..36918b52cd3 --- /dev/null +++ b/tests/ui/consts/const-eval/const_fn_target_feature.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const_fn_target_feature.rs:10:24 + | +LL | const B: () = unsafe { avx2_fn() }; + | ^^^^^^^^^ calling a function that requires unavailable target features: avx2 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`.