From 3a0ed0c6e3209ae1bce3079eea944c07b58f225f Mon Sep 17 00:00:00 2001 From: Orion Gonzalez Date: Wed, 2 Oct 2024 23:35:17 +0200 Subject: [PATCH 1/7] add direnv to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d6d8b99f6023c..2f88b27530128 100644 --- a/.gitignore +++ b/.gitignore @@ -86,4 +86,8 @@ package.json ## Rustdoc GUI tests tests/rustdoc-gui/src/**.lock +## direnv +.envrc +.direnv/ + # Before adding new lines, see the comment at the top. From 510e262deb6c5eba94e0aad2f609448271f80264 Mon Sep 17 00:00:00 2001 From: Orion Gonzalez Date: Wed, 2 Oct 2024 23:35:48 +0200 Subject: [PATCH 2/7] add nix files to gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 2f88b27530128..b170dca88fa95 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,9 @@ tests/rustdoc-gui/src/**.lock .envrc .direnv/ +## nix +flake.nix +flake.lock +default.nix + # Before adding new lines, see the comment at the top. From 83d0d9f292d4c98d26cd007f294ab91789b1378d Mon Sep 17 00:00:00 2001 From: ismailarilik Date: Thu, 3 Oct 2024 12:47:08 +0300 Subject: [PATCH 3/7] Handle `rustc_query_impl` cases of `rustc::potential_query_instability` lint --- compiler/rustc_query_impl/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 69742bb49b1e8..df898e0587ff9 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -2,7 +2,7 @@ // tidy-alphabetical-start #![allow(internal_features)] -#![allow(rustc::potential_query_instability, unused_parens)] +#![allow(unused_parens)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] #![feature(min_specialization)] From 8e382ba022fc7f8f6f7e0abca5e8052039a81202 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 3 Oct 2024 16:53:51 +1000 Subject: [PATCH 4/7] Avoid ICE in coverage builds with bad `#[coverage(..)]` attributes This code can sometimes witness malformed coverage attributes in builds that are going to fail, so use `span_delayed_bug` to avoid an inappropriate ICE in that case. --- .../rustc_mir_transform/src/coverage/query.rs | 3 ++- tests/crashes/127880.rs | 5 ---- .../ui/coverage-attr/bad-attr-ice.feat.stderr | 15 +++++++++++ .../coverage-attr/bad-attr-ice.nofeat.stderr | 26 +++++++++++++++++++ tests/ui/coverage-attr/bad-attr-ice.rs | 16 ++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) delete mode 100644 tests/crashes/127880.rs create mode 100644 tests/ui/coverage-attr/bad-attr-ice.feat.stderr create mode 100644 tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr create mode 100644 tests/ui/coverage-attr/bad-attr-ice.rs diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index e65a5fdd5e7f1..df151f8cca35e 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -63,7 +63,8 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { Some([item]) if item.has_name(sym::on) => return true, Some(_) | None => { // Other possibilities should have been rejected by `rustc_parse::validate_attr`. - tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute"); + // Use `span_delayed_bug` to avoid an ICE in failing builds (#127880). + tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute"); } } } diff --git a/tests/crashes/127880.rs b/tests/crashes/127880.rs deleted file mode 100644 index 6c625eac6914a..0000000000000 --- a/tests/crashes/127880.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ known-bug: #127880 -//@ compile-flags: -Cinstrument-coverage - -#[coverage] -fn main() {} diff --git a/tests/ui/coverage-attr/bad-attr-ice.feat.stderr b/tests/ui/coverage-attr/bad-attr-ice.feat.stderr new file mode 100644 index 0000000000000..9e3cd41c2777d --- /dev/null +++ b/tests/ui/coverage-attr/bad-attr-ice.feat.stderr @@ -0,0 +1,15 @@ +error: malformed `coverage` attribute input + --> $DIR/bad-attr-ice.rs:10:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: aborting due to 1 previous error + diff --git a/tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr b/tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr new file mode 100644 index 0000000000000..d73636e158bae --- /dev/null +++ b/tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr @@ -0,0 +1,26 @@ +error: malformed `coverage` attribute input + --> $DIR/bad-attr-ice.rs:10:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error[E0658]: the `#[coverage]` attribute is an experimental feature + --> $DIR/bad-attr-ice.rs:10:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | + = note: see issue #84605 for more information + = help: add `#![feature(coverage_attribute)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/coverage-attr/bad-attr-ice.rs b/tests/ui/coverage-attr/bad-attr-ice.rs new file mode 100644 index 0000000000000..ae4d27d65ebd6 --- /dev/null +++ b/tests/ui/coverage-attr/bad-attr-ice.rs @@ -0,0 +1,16 @@ +#![cfg_attr(feat, feature(coverage_attribute))] +//@ revisions: feat nofeat +//@ compile-flags: -Cinstrument-coverage +//@ needs-profiler-support + +// Malformed `#[coverage(..)]` attributes should not cause an ICE when built +// with `-Cinstrument-coverage`. +// Regression test for . + +#[coverage] +//~^ ERROR malformed `coverage` attribute input +//[nofeat]~| the `#[coverage]` attribute is an experimental feature +fn main() {} + +// FIXME(#130766): When the `#[coverage(..)]` attribute is stabilized, +// get rid of the revisions and just make this a normal test. From d47e388843f682f57262f020edd9909c850a0c49 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Thu, 3 Oct 2024 22:15:52 +0800 Subject: [PATCH 5/7] Avoid emptiness check in `PeekMut::pop` --- library/alloc/src/collections/binary_heap/mod.rs | 5 ++++- tests/codegen/binary-heap-peek-mut-pop-no-panic.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/codegen/binary-heap-peek-mut-pop-no-panic.rs diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 5e59abf54ee0f..59f10b09c73fd 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> { // the caller could've mutated the element. It is removed from the // heap on the next line and pop() is not sensitive to its value. } - this.heap.pop().unwrap() + + // SAFETY: Have a `PeekMut` element proves that the associated binary heap being non-empty, + // so the `pop` operation will not fail. + unsafe { this.heap.pop().unwrap_unchecked() } } } diff --git a/tests/codegen/binary-heap-peek-mut-pop-no-panic.rs b/tests/codegen/binary-heap-peek-mut-pop-no-panic.rs new file mode 100644 index 0000000000000..9cf4f210e527a --- /dev/null +++ b/tests/codegen/binary-heap-peek-mut-pop-no-panic.rs @@ -0,0 +1,13 @@ +//@ compile-flags: -O +//@ ignore-debug +#![crate_type = "lib"] + +use std::collections::binary_heap::PeekMut; + +// CHECK-LABEL: @peek_mut_pop +#[no_mangle] +pub fn peek_mut_pop(peek_mut: PeekMut) -> u32 { + // CHECK-NOT: panic + // CHECK-NOT: unwrap_failed + PeekMut::pop(peek_mut) +} From 417b55b9bbc1a5d474d80256f42f1f9bb8626e2b Mon Sep 17 00:00:00 2001 From: clubby789 Date: Thu, 3 Oct 2024 14:55:46 +0000 Subject: [PATCH 6/7] JumpThreading: Add test for incorrect Not behaviour --- ...ing.not_int.JumpThreading.panic-abort.diff | 46 +++++++++++++++++++ ...ng.not_int.JumpThreading.panic-unwind.diff | 46 +++++++++++++++++++ tests/mir-opt/jump_threading.rs | 11 +++++ 3 files changed, 103 insertions(+) create mode 100644 tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff create mode 100644 tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff diff --git a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff new file mode 100644 index 0000000000000..e2d1e295f533a --- /dev/null +++ b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff @@ -0,0 +1,46 @@ +- // MIR for `not_int` before JumpThreading ++ // MIR for `not_int` after JumpThreading + + fn not_int() -> i32 { + let mut _0: i32; + let _1: i32; + let mut _2: bool; + let mut _3: i32; + let mut _4: i32; + scope 1 { + debug a => _1; + } + + bb0: { + StorageLive(_1); + _1 = const 1_i32; + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = copy _1; + _3 = Not(move _4); + StorageDead(_4); + _2 = Eq(move _3, const 0_i32); +- switchInt(move _2) -> [0: bb2, otherwise: bb1]; ++ goto -> bb1; + } + + bb1: { + StorageDead(_3); + _0 = const 1_i32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 0_i32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff new file mode 100644 index 0000000000000..e2d1e295f533a --- /dev/null +++ b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff @@ -0,0 +1,46 @@ +- // MIR for `not_int` before JumpThreading ++ // MIR for `not_int` after JumpThreading + + fn not_int() -> i32 { + let mut _0: i32; + let _1: i32; + let mut _2: bool; + let mut _3: i32; + let mut _4: i32; + scope 1 { + debug a => _1; + } + + bb0: { + StorageLive(_1); + _1 = const 1_i32; + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = copy _1; + _3 = Not(move _4); + StorageDead(_4); + _2 = Eq(move _3, const 0_i32); +- switchInt(move _2) -> [0: bb2, otherwise: bb1]; ++ goto -> bb1; + } + + bb1: { + StorageDead(_3); + _0 = const 1_i32; + goto -> bb3; + } + + bb2: { + StorageDead(_3); + _0 = const 0_i32; + goto -> bb3; + } + + bb3: { + StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index 9487a4e7e5ffe..f62461e225b43 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -531,6 +531,15 @@ fn floats() -> u32 { if x == 0.0 { 0 } else { 1 } } +fn not_int() -> i32 { + // CHECK-LABEL: fn not_int( + + // Test for issue #131195, where !a == b is assumed to be equivalent to a != b + // This is only the case for bools + let a = 1; + if !a == 0 { 1 } else { 0 } +} + fn main() { // CHECK-LABEL: fn main( too_complex(Ok(0)); @@ -546,6 +555,7 @@ fn main() { aggregate(7); assume(7, false); floats(); + not_int(); } // EMIT_MIR jump_threading.too_complex.JumpThreading.diff @@ -562,3 +572,4 @@ fn main() { // EMIT_MIR jump_threading.assume.JumpThreading.diff // EMIT_MIR jump_threading.aggregate_copy.JumpThreading.diff // EMIT_MIR jump_threading.floats.JumpThreading.diff +// EMIT_MIR jump_threading.not_int.JumpThreading.diff From fd35e820bbb0385c61246e48103437a98322c491 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Thu, 3 Oct 2024 15:10:47 +0000 Subject: [PATCH 7/7] JumpThreading: fix bitwise Not on non-booleans --- compiler/rustc_middle/src/ty/consts/int.rs | 5 +++++ .../rustc_mir_transform/src/jump_threading.rs | 6 ++---- ...ing.not_int.JumpThreading.panic-abort.diff | 2 +- ...ng.not_int.JumpThreading.panic-unwind.diff | 2 +- tests/mir-opt/jump_threading.rs | 6 ++++++ ..._forward.PreCodegen.after.panic-unwind.mir | 19 +++++++++++-------- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 1732374ab8c26..a278fc2e7fa4f 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -398,6 +398,11 @@ impl ScalarInt { pub fn to_f128(self) -> Quad { self.to_float() } + + #[inline] + pub fn bitwise_not(self) -> Self { + Self { data: self.size().truncate(!self.data), size: self.size } + } } macro_rules! from_x_for_scalar_int { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 1844b97887ab9..0c0a354b48128 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -150,10 +150,8 @@ impl Condition { } fn inv(mut self) -> Self { - self.polarity = match self.polarity { - Polarity::Eq => Polarity::Ne, - Polarity::Ne => Polarity::Eq, - }; + self.value = self.value.bitwise_not(); + self } } diff --git a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff index e2d1e295f533a..beb5cd59c8a15 100644 --- a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-abort.diff @@ -22,7 +22,7 @@ StorageDead(_4); _2 = Eq(move _3, const 0_i32); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ goto -> bb1; ++ goto -> bb2; } bb1: { diff --git a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff index e2d1e295f533a..beb5cd59c8a15 100644 --- a/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.not_int.JumpThreading.panic-unwind.diff @@ -22,7 +22,7 @@ StorageDead(_4); _2 = Eq(move _3, const 0_i32); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; -+ goto -> bb1; ++ goto -> bb2; } bb1: { diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index f62461e225b43..1a1f658640581 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -533,7 +533,13 @@ fn floats() -> u32 { fn not_int() -> i32 { // CHECK-LABEL: fn not_int( + // CHECK: goto -> bb2 + // CHECK-LABEL: bb1: { + // _0 = const 1_i32; + + // CHECK-LABEL: bb2: { + // _0 = const 0_i32; // Test for issue #131195, where !a == b is assumed to be equivalent to a != b // This is only the case for bools let a = 1; diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir index bf1ffd1ef328d..9fbfd99a3850f 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir @@ -33,7 +33,7 @@ fn step_forward(_1: u16, _2: usize) -> u16 { StorageLive(_4); StorageLive(_3); _3 = Gt(copy _2, const 65535_usize); - switchInt(move _3) -> [0: bb1, otherwise: bb5]; + switchInt(move _3) -> [0: bb1, otherwise: bb6]; } bb1: { @@ -54,27 +54,30 @@ fn step_forward(_1: u16, _2: usize) -> u16 { bb3: { StorageDead(_5); StorageDead(_6); - StorageDead(_7); - goto -> bb7; + goto -> bb5; } bb4: { StorageDead(_5); StorageDead(_6); - StorageDead(_7); - goto -> bb6; + goto -> bb5; } bb5: { - StorageDead(_3); - goto -> bb6; + StorageDead(_7); + goto -> bb7; } bb6: { - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::::MAX, const 1_u16) -> [success: bb7, unwind continue]; + StorageDead(_3); + goto -> bb7; } bb7: { + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::::MAX, const 1_u16) -> [success: bb8, unwind continue]; + } + + bb8: { StorageLive(_8); _8 = copy _2 as u16 (IntToInt); _0 = Add(copy _1, copy _8);