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 5adcbf84da5a0..5aa26796a691c 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 0000000000000..3804102966e57 --- /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 0000000000000..5d0cae8cc2a9e --- /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 5aa26796a691c..3034740fab577 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 0000000000000..d85a7a3de4895 --- /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 0000000000000..4fc6e9bcf7dff --- /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 0000000000000..5c463780ac8c1 --- /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 0000000000000..f10052b6df069 --- /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 3034740fab577..1faa9ad0d0da4 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 d85a7a3de4895..0da4b44a96839 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 4fc6e9bcf7dff..197b2f082e5a0 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 5c463780ac8c1..25f45104d6aa1 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 f10052b6df069..5de3ee6654ad9 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 3804102966e57..92ff264cd2b8e 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 5d0cae8cc2a9e..4acf2f0f4d1e5 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) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^