From 1f40580f626f71cdb6bdd7ca888c0d12941662d1 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 13:53:43 +0200 Subject: [PATCH 1/4] Function arguments should never get promoted --- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/test/ui/consts/const_arg_wrapper.rs | 10 ++++++++++ src/test/ui/consts/const_arg_wrapper.stderr | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const_arg_wrapper.rs create mode 100644 src/test/ui/consts/const_arg_wrapper.stderr diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 5adcbf84da5..5aa26796a69 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -639,7 +639,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { per_local.insert(local); } } - cx.per_local[IsNotPromotable].insert(local); + cx.per_local[IsNotConst].insert(local); } LocalKind::Var if mode == Mode::Fn => { diff --git a/src/test/ui/consts/const_arg_wrapper.rs b/src/test/ui/consts/const_arg_wrapper.rs new file mode 100644 index 00000000000..3804102966e --- /dev/null +++ b/src/test/ui/consts/const_arg_wrapper.rs @@ -0,0 +1,10 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i, imm8: i32) -> __m128i { + _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_wrapper.stderr b/src/test/ui/consts/const_arg_wrapper.stderr new file mode 100644 index 00000000000..5d0cae8cc2a --- /dev/null +++ b/src/test/ui/consts/const_arg_wrapper.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_wrapper.rs:7:5 + | +LL | _mm_clmulepi64_si128(a, b, imm8) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From 65a45dd99dac63a2b0296042726ff61fe2399353 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 13:56:52 +0200 Subject: [PATCH 2/4] Add more regression tests for accidental promotion --- src/librustc_mir/transform/qualify_consts.rs | 4 ++-- src/test/ui/consts/const_arg_local.rs | 11 +++++++++++ src/test/ui/consts/const_arg_local.stderr | 8 ++++++++ src/test/ui/consts/const_arg_promotable.rs | 10 ++++++++++ src/test/ui/consts/const_arg_promotable.stderr | 8 ++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/const_arg_local.rs create mode 100644 src/test/ui/consts/const_arg_local.stderr create mode 100644 src/test/ui/consts/const_arg_promotable.rs create mode 100644 src/test/ui/consts/const_arg_promotable.stderr diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 5aa26796a69..3034740fab5 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -647,7 +647,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { } LocalKind::Temp if !temps[local].is_promotable() => { - cx.per_local[IsNotPromotable].insert(local); + cx.per_local[IsNotConst].insert(local); } _ => {} @@ -825,7 +825,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { // be replaced with calling `insert` to re-set the bit). if kind == LocalKind::Temp { if !self.temp_promotion_state[index].is_promotable() { - assert!(self.cx.per_local[IsNotPromotable].contains(index)); + assert!(self.cx.per_local[IsNotConst].contains(index)); } } } diff --git a/src/test/ui/consts/const_arg_local.rs b/src/test/ui/consts/const_arg_local.rs new file mode 100644 index 00000000000..d85a7a3de48 --- /dev/null +++ b/src/test/ui/consts/const_arg_local.rs @@ -0,0 +1,11 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i) -> __m128i { + let imm8 = 3; + _mm_clmulepi64_si128(a, b, imm8) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_local.stderr b/src/test/ui/consts/const_arg_local.stderr new file mode 100644 index 00000000000..4fc6e9bcf7d --- /dev/null +++ b/src/test/ui/consts/const_arg_local.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_local.rs:8:5 + | +LL | _mm_clmulepi64_si128(a, b, imm8) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const_arg_promotable.rs b/src/test/ui/consts/const_arg_promotable.rs new file mode 100644 index 00000000000..5c463780ac8 --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable.rs @@ -0,0 +1,10 @@ +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +unsafe fn pclmul(a: __m128i, b: __m128i) -> __m128i { + _mm_clmulepi64_si128(a, b, *&mut 42) //~ ERROR argument 3 is required to be a constant +} + +fn main() {} diff --git a/src/test/ui/consts/const_arg_promotable.stderr b/src/test/ui/consts/const_arg_promotable.stderr new file mode 100644 index 00000000000..f10052b6df0 --- /dev/null +++ b/src/test/ui/consts/const_arg_promotable.stderr @@ -0,0 +1,8 @@ +error: argument 3 is required to be a constant + --> $DIR/const_arg_promotable.rs:7:5 + | +LL | _mm_clmulepi64_si128(a, b, *&mut 42) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From 54ea7f726ed2d04460687c82a56a54ec8c7e96d7 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 5 Apr 2019 17:00:21 +0200 Subject: [PATCH 3/4] Update comment --- src/librustc_mir/transform/qualify_consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3034740fab5..1faa9ad0d0d 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -817,7 +817,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { } } - // Ensure the `IsNotPromotable` qualification is preserved. + // Ensure the `IsNotConst` qualification is preserved. // NOTE(eddyb) this is actually unnecessary right now, as // we never replace the local's qualif, but we might in // the future, and so it serves to catch changes that unset From 01e83943f9dbcd421826eaed5fa04df8e1bb5570 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 7 Apr 2019 21:46:39 +0200 Subject: [PATCH 4/4] Only run SIMD tests on x86 --- src/test/ui/consts/const_arg_local.rs | 2 ++ src/test/ui/consts/const_arg_local.stderr | 2 +- src/test/ui/consts/const_arg_promotable.rs | 2 ++ src/test/ui/consts/const_arg_promotable.stderr | 2 +- src/test/ui/consts/const_arg_wrapper.rs | 2 ++ src/test/ui/consts/const_arg_wrapper.stderr | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const_arg_local.rs b/src/test/ui/consts/const_arg_local.rs index d85a7a3de48..0da4b44a968 100644 --- a/src/test/ui/consts/const_arg_local.rs +++ b/src/test/ui/consts/const_arg_local.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_local.stderr b/src/test/ui/consts/const_arg_local.stderr index 4fc6e9bcf7d..197b2f082e5 100644 --- a/src/test/ui/consts/const_arg_local.stderr +++ b/src/test/ui/consts/const_arg_local.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_local.rs:8:5 + --> $DIR/const_arg_local.rs:10:5 | LL | _mm_clmulepi64_si128(a, b, imm8) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const_arg_promotable.rs b/src/test/ui/consts/const_arg_promotable.rs index 5c463780ac8..25f45104d6a 100644 --- a/src/test/ui/consts/const_arg_promotable.rs +++ b/src/test/ui/consts/const_arg_promotable.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_promotable.stderr b/src/test/ui/consts/const_arg_promotable.stderr index f10052b6df0..5de3ee6654a 100644 --- a/src/test/ui/consts/const_arg_promotable.stderr +++ b/src/test/ui/consts/const_arg_promotable.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_promotable.rs:7:5 + --> $DIR/const_arg_promotable.rs:9:5 | LL | _mm_clmulepi64_si128(a, b, *&mut 42) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const_arg_wrapper.rs b/src/test/ui/consts/const_arg_wrapper.rs index 3804102966e..92ff264cd2b 100644 --- a/src/test/ui/consts/const_arg_wrapper.rs +++ b/src/test/ui/consts/const_arg_wrapper.rs @@ -1,3 +1,5 @@ +// only-x86_64 + #[cfg(target_arch = "x86")] use std::arch::x86::*; #[cfg(target_arch = "x86_64")] diff --git a/src/test/ui/consts/const_arg_wrapper.stderr b/src/test/ui/consts/const_arg_wrapper.stderr index 5d0cae8cc2a..4acf2f0f4d1 100644 --- a/src/test/ui/consts/const_arg_wrapper.stderr +++ b/src/test/ui/consts/const_arg_wrapper.stderr @@ -1,5 +1,5 @@ error: argument 3 is required to be a constant - --> $DIR/const_arg_wrapper.rs:7:5 + --> $DIR/const_arg_wrapper.rs:9:5 | LL | _mm_clmulepi64_si128(a, b, imm8) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^