Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4ddfadb

Browse files
committed
Auto merge of rust-lang#117192 - saethlin:leaves-can-assert, r=<try>
Don't treat asserts as a call in cross-crate inlining r? `@ghost`
2 parents 7ac9a3a + ffa51c9 commit 4ddfadb

File tree

6 files changed

+87
-86
lines changed

6 files changed

+87
-86
lines changed

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
9393
}
9494
}
9595
}
96-
TerminatorKind::Call { unwind, .. } => {
97-
self.calls += 1;
96+
TerminatorKind::Call { unwind, target, .. } => {
97+
if target.is_some() {
98+
self.calls += 1;
99+
}
98100
if let UnwindAction::Cleanup(_) = unwind {
99101
self.landing_pads += 1;
100102
}
101103
}
102104
TerminatorKind::Assert { unwind, .. } => {
103-
self.calls += 1;
104105
if let UnwindAction::Cleanup(_) = unwind {
105106
self.landing_pads += 1;
106107
}

tests/codegen-units/item-collection/implicit-panic-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ impl Div for i32 {
4848
}
4949

5050
#[allow(unconditional_panic)]
51+
#[inline(never)]
5152
pub fn foo() {
5253
// This implicitly generates a panic call.
5354
let _ = 1 / 0;
5455
}
5556

5657
//~ MONO_ITEM fn foo
57-
//~ MONO_ITEM fn <i32 as Div>::div
5858
//~ MONO_ITEM fn panic

tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,35 @@
33

44
fn main() -> () {
55
let mut _0: ();
6-
let _1: ();
7-
let mut _2: ((), u8, u8);
6+
let mut _3: ();
7+
let mut _4: u8;
8+
let mut _5: u8;
9+
scope 1 (inlined encode) {
10+
debug ((this: ((), u8, u8)).0: ()) => _3;
11+
debug ((this: ((), u8, u8)).1: u8) => _4;
12+
debug ((this: ((), u8, u8)).2: u8) => _5;
13+
let mut _1: u8;
14+
let mut _2: !;
15+
}
816

917
bb0: {
10-
StorageLive(_2);
11-
- _2 = (const (), const 0_u8, const 0_u8);
12-
- _1 = encode(move _2) -> [return: bb1, unwind unreachable];
13-
+ _2 = const ((), 0_u8, 0_u8);
14-
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable];
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_3 = const ();
21+
_4 = const 0_u8;
22+
_5 = const 0_u8;
23+
- switchInt(_5) -> [0: bb1, otherwise: bb2];
24+
+ switchInt(const 0_u8) -> [0: bb1, otherwise: bb2];
1525
}
1626

1727
bb1: {
18-
StorageDead(_2);
28+
StorageDead(_3);
29+
StorageDead(_4);
1930
return;
2031
}
21-
+ }
22-
+
23-
+ ALLOC0 (size: 2, align: 1) {
24-
+ 00 00 │ ..
25-
+ }
26-
+
27-
+ ALLOC1 (size: 2, align: 1) {
28-
+ 00 00 │ ..
32+
33+
bb2: {
34+
_2 = core::panicking::panic(const "assertion failed: this.2 == 0") -> unwind unreachable;
35+
}
2936
}
3037

tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,35 @@
33

44
fn main() -> () {
55
let mut _0: ();
6-
let _1: ();
7-
let mut _2: ((), u8, u8);
6+
let mut _3: ();
7+
let mut _4: u8;
8+
let mut _5: u8;
9+
scope 1 (inlined encode) {
10+
debug ((this: ((), u8, u8)).0: ()) => _3;
11+
debug ((this: ((), u8, u8)).1: u8) => _4;
12+
debug ((this: ((), u8, u8)).2: u8) => _5;
13+
let mut _1: u8;
14+
let mut _2: !;
15+
}
816

917
bb0: {
10-
StorageLive(_2);
11-
- _2 = (const (), const 0_u8, const 0_u8);
12-
- _1 = encode(move _2) -> [return: bb1, unwind continue];
13-
+ _2 = const ((), 0_u8, 0_u8);
14-
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue];
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_3 = const ();
21+
_4 = const 0_u8;
22+
_5 = const 0_u8;
23+
- switchInt(_5) -> [0: bb1, otherwise: bb2];
24+
+ switchInt(const 0_u8) -> [0: bb1, otherwise: bb2];
1525
}
1626

1727
bb1: {
18-
StorageDead(_2);
28+
StorageDead(_3);
29+
StorageDead(_4);
1930
return;
2031
}
21-
+ }
22-
+
23-
+ ALLOC0 (size: 2, align: 1) {
24-
+ 00 00 │ ..
25-
+ }
26-
+
27-
+ ALLOC1 (size: 2, align: 1) {
28-
+ 00 00 │ ..
32+
33+
bb2: {
34+
_2 = core::panicking::panic(const "assertion failed: this.2 == 0") -> unwind continue;
35+
}
2936
}
3037

tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,30 @@
33

44
fn main() -> () {
55
let mut _0: ();
6-
let _1: ();
7-
let mut _2: ((u8, u8),);
8-
let mut _3: (u8, u8);
6+
let mut _3: u8;
7+
let mut _4: u8;
8+
let mut _5: u8;
9+
let mut _6: u8;
10+
scope 1 (inlined test) {
11+
debug (((this: ((u8, u8),)).0: (u8, u8)).0: u8) => _5;
12+
debug (((this: ((u8, u8),)).0: (u8, u8)).1: u8) => _6;
13+
let mut _1: u8;
14+
let mut _2: !;
15+
}
916

1017
bb0: {
11-
StorageLive(_2);
12-
StorageLive(_3);
13-
- _3 = (const 1_u8, const 2_u8);
14-
- _2 = (move _3,);
15-
+ _3 = const (1_u8, 2_u8);
16-
+ _2 = const ((1_u8, 2_u8),);
17-
StorageDead(_3);
18-
- _1 = test(move _2) -> [return: bb1, unwind unreachable];
19-
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable];
18+
_5 = const 1_u8;
19+
_6 = const 2_u8;
20+
- switchInt(_5) -> [1: bb1, otherwise: bb2];
21+
+ switchInt(const 1_u8) -> [1: bb1, otherwise: bb2];
2022
}
2123

2224
bb1: {
23-
StorageDead(_2);
2425
return;
2526
}
26-
+ }
27-
+
28-
+ ALLOC0 (size: 2, align: 1) {
29-
+ 01 02 │ ..
30-
+ }
31-
+
32-
+ ALLOC1 (size: 2, align: 1) {
33-
+ 01 02 │ ..
34-
+ }
35-
+
36-
+ ALLOC2 (size: 2, align: 1) {
37-
+ 01 02 │ ..
27+
28+
bb2: {
29+
_2 = core::panicking::panic(const "assertion failed: (this.0).0 == 1") -> unwind unreachable;
30+
}
3831
}
3932

tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,30 @@
33

44
fn main() -> () {
55
let mut _0: ();
6-
let _1: ();
7-
let mut _2: ((u8, u8),);
8-
let mut _3: (u8, u8);
6+
let mut _3: u8;
7+
let mut _4: u8;
8+
let mut _5: u8;
9+
let mut _6: u8;
10+
scope 1 (inlined test) {
11+
debug (((this: ((u8, u8),)).0: (u8, u8)).0: u8) => _5;
12+
debug (((this: ((u8, u8),)).0: (u8, u8)).1: u8) => _6;
13+
let mut _1: u8;
14+
let mut _2: !;
15+
}
916

1017
bb0: {
11-
StorageLive(_2);
12-
StorageLive(_3);
13-
- _3 = (const 1_u8, const 2_u8);
14-
- _2 = (move _3,);
15-
+ _3 = const (1_u8, 2_u8);
16-
+ _2 = const ((1_u8, 2_u8),);
17-
StorageDead(_3);
18-
- _1 = test(move _2) -> [return: bb1, unwind continue];
19-
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue];
18+
_5 = const 1_u8;
19+
_6 = const 2_u8;
20+
- switchInt(_5) -> [1: bb1, otherwise: bb2];
21+
+ switchInt(const 1_u8) -> [1: bb1, otherwise: bb2];
2022
}
2123

2224
bb1: {
23-
StorageDead(_2);
2425
return;
2526
}
26-
+ }
27-
+
28-
+ ALLOC0 (size: 2, align: 1) {
29-
+ 01 02 │ ..
30-
+ }
31-
+
32-
+ ALLOC1 (size: 2, align: 1) {
33-
+ 01 02 │ ..
34-
+ }
35-
+
36-
+ ALLOC2 (size: 2, align: 1) {
37-
+ 01 02 │ ..
27+
28+
bb2: {
29+
_2 = core::panicking::panic(const "assertion failed: (this.0).0 == 1") -> unwind continue;
30+
}
3831
}
3932

0 commit comments

Comments
 (0)