Fortify test.

This commit is contained in:
Camille GILLOT 2025-06-21 09:03:40 +00:00 committed by Camille Gillot
parent 54f417673c
commit ee16aed94c
3 changed files with 87 additions and 56 deletions

View file

@ -1,51 +1,50 @@
- // MIR for `aggregate` before JumpThreading - // MIR for `aggregate` before JumpThreading
+ // MIR for `aggregate` after JumpThreading + // MIR for `aggregate` after JumpThreading
fn aggregate(_1: u8) -> u8 { fn aggregate() -> u8 {
debug x => _1;
let mut _0: u8; let mut _0: u8;
let _1: u8;
let _2: u8; let _2: u8;
let _3: u8; let mut _3: (u8, u8);
let mut _4: (u8, u8); let mut _4: bool;
let mut _5: bool; let mut _5: u8;
let mut _6: u8;
scope 1 { scope 1 {
debug a => _2; debug a => _1;
debug b => _3; debug b => _2;
} }
bb0: { bb0: {
StorageLive(_4);
_4 = const aggregate::FOO;
StorageLive(_2);
_2 = copy (_4.0: u8);
StorageLive(_3); StorageLive(_3);
_3 = copy (_4.1: u8); _3 = const aggregate::FOO;
StorageDead(_4); StorageLive(_1);
_1 = copy (_3.0: u8);
StorageLive(_2);
_2 = copy (_3.1: u8);
StorageDead(_3);
StorageLive(_4);
StorageLive(_5); StorageLive(_5);
StorageLive(_6); _5 = copy _1;
_6 = copy _2; _4 = Eq(move _5, const 7_u8);
_5 = Eq(move _6, const 7_u8); - switchInt(move _4) -> [0: bb2, otherwise: bb1];
- switchInt(move _5) -> [0: bb2, otherwise: bb1];
+ goto -> bb2; + goto -> bb2;
} }
bb1: { bb1: {
StorageDead(_6); StorageDead(_5);
_0 = copy _3;
goto -> bb3;
}
bb2: {
StorageDead(_6);
_0 = copy _2; _0 = copy _2;
goto -> bb3; goto -> bb3;
} }
bb3: { bb2: {
StorageDead(_5); StorageDead(_5);
StorageDead(_3); _0 = copy _1;
goto -> bb3;
}
bb3: {
StorageDead(_4);
StorageDead(_2); StorageDead(_2);
StorageDead(_1);
return; return;
} }
} }

View file

@ -1,51 +1,50 @@
- // MIR for `aggregate` before JumpThreading - // MIR for `aggregate` before JumpThreading
+ // MIR for `aggregate` after JumpThreading + // MIR for `aggregate` after JumpThreading
fn aggregate(_1: u8) -> u8 { fn aggregate() -> u8 {
debug x => _1;
let mut _0: u8; let mut _0: u8;
let _1: u8;
let _2: u8; let _2: u8;
let _3: u8; let mut _3: (u8, u8);
let mut _4: (u8, u8); let mut _4: bool;
let mut _5: bool; let mut _5: u8;
let mut _6: u8;
scope 1 { scope 1 {
debug a => _2; debug a => _1;
debug b => _3; debug b => _2;
} }
bb0: { bb0: {
StorageLive(_4);
_4 = const aggregate::FOO;
StorageLive(_2);
_2 = copy (_4.0: u8);
StorageLive(_3); StorageLive(_3);
_3 = copy (_4.1: u8); _3 = const aggregate::FOO;
StorageDead(_4); StorageLive(_1);
_1 = copy (_3.0: u8);
StorageLive(_2);
_2 = copy (_3.1: u8);
StorageDead(_3);
StorageLive(_4);
StorageLive(_5); StorageLive(_5);
StorageLive(_6); _5 = copy _1;
_6 = copy _2; _4 = Eq(move _5, const 7_u8);
_5 = Eq(move _6, const 7_u8); - switchInt(move _4) -> [0: bb2, otherwise: bb1];
- switchInt(move _5) -> [0: bb2, otherwise: bb1];
+ goto -> bb2; + goto -> bb2;
} }
bb1: { bb1: {
StorageDead(_6); StorageDead(_5);
_0 = copy _3;
goto -> bb3;
}
bb2: {
StorageDead(_6);
_0 = copy _2; _0 = copy _2;
goto -> bb3; goto -> bb3;
} }
bb3: { bb2: {
StorageDead(_5); StorageDead(_5);
StorageDead(_3); _0 = copy _1;
goto -> bb3;
}
bb3: {
StorageDead(_4);
StorageDead(_2); StorageDead(_2);
StorageDead(_1);
return; return;
} }
} }

View file

@ -449,9 +449,17 @@ fn disappearing_bb(x: u8) -> u8 {
} }
/// Verify that we can thread jumps when we assign from an aggregate constant. /// Verify that we can thread jumps when we assign from an aggregate constant.
fn aggregate(x: u8) -> u8 { fn aggregate() -> u8 {
// CHECK-LABEL: fn aggregate( // CHECK-LABEL: fn aggregate(
// CHECK: debug a => [[a:_.*]];
// CHECK: debug b => [[b:_.*]];
// CHECK-NOT: switchInt( // CHECK-NOT: switchInt(
// CHECK: [[a2:_.*]] = copy [[a]];
// CHECK: {{_.*}} = Eq(move [[a2]], const 7_u8);
// CHECK-NEXT: goto -> [[bb:bb.*]];
// CHECK: [[bb]]: {
// CHECK-NOT: }
// CHECK: _0 = copy [[a]];
const FOO: (u8, u8) = (5, 13); const FOO: (u8, u8) = (5, 13);
@ -508,7 +516,16 @@ fn assume(a: u8, b: bool) -> u8 {
/// Verify that jump threading succeeds seeing through copies of aggregates. /// Verify that jump threading succeeds seeing through copies of aggregates.
fn aggregate_copy() -> u32 { fn aggregate_copy() -> u32 {
// CHECK-LABEL: fn aggregate_copy( // CHECK-LABEL: fn aggregate_copy(
// CHECK: debug a => [[a:_.*]];
// CHECK: debug b => [[b:_.*]];
// CHECK: debug c => [[c:_.*]];
// CHECK-NOT: switchInt( // CHECK-NOT: switchInt(
// CHECK: [[c2:_.*]] = copy [[c]];
// CHECK: {{_.*}} = Eq(move [[c2]], const 2_u32);
// CHECK-NEXT: goto -> [[bb:bb.*]];
// CHECK: [[bb]]: {
// CHECK-NOT: }
// CHECK: _0 = const 13_u32;
const Foo: (u32, u32) = (5, 3); const Foo: (u32, u32) = (5, 3);
@ -532,6 +549,14 @@ fn floats() -> u32 {
pub fn bitwise_not() -> i32 { pub fn bitwise_not() -> i32 {
// CHECK-LABEL: fn bitwise_not( // CHECK-LABEL: fn bitwise_not(
// CHECK: debug a => [[a:_.*]];
// CHECK: [[a2:_.*]] = copy [[a]];
// CHECK: [[not:_.*]] = Not(move [[a2]]);
// CHECK: {{_.*}} = Eq(move [[not]], const 0_i32);
// CHECK-NEXT: goto -> [[bb:bb.*]];
// CHECK: [[bb]]: {
// CHECK-NOT: }
// CHECK: _0 = const 0_i32;
// Test for #131195, which was optimizing `!a == b` into `a != b`. // Test for #131195, which was optimizing `!a == b` into `a != b`.
let a = 1; let a = 1;
@ -540,6 +565,14 @@ pub fn bitwise_not() -> i32 {
pub fn logical_not() -> i32 { pub fn logical_not() -> i32 {
// CHECK-LABEL: fn logical_not( // CHECK-LABEL: fn logical_not(
// CHECK: debug a => [[a:_.*]];
// CHECK: [[a2:_.*]] = copy [[a]];
// CHECK: [[not:_.*]] = Not(move [[a2]]);
// CHECK: {{_.*}} = Eq(move [[not]], const true);
// CHECK-NEXT: goto -> [[bb:bb.*]];
// CHECK: [[bb]]: {
// CHECK-NOT: }
// CHECK: _0 = const 1_i32;
let a = false; let a = false;
if !a == true { 1 } else { 0 } if !a == true { 1 } else { 0 }
@ -557,7 +590,7 @@ fn main() {
mutable_ref(); mutable_ref();
renumbered_bb(true); renumbered_bb(true);
disappearing_bb(7); disappearing_bb(7);
aggregate(7); aggregate();
assume(7, false); assume(7, false);
floats(); floats();
bitwise_not(); bitwise_not();