-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for const type_id misoptimization
- Loading branch information
Lukas Markeffsky
committed
Feb 11, 2025
1 parent
4bb6ec0
commit 4898753
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
- // MIR for `cursed_is_i32` before GVN | ||
+ // MIR for `cursed_is_i32` after GVN | ||
|
||
fn cursed_is_i32() -> bool { | ||
let mut _0: bool; | ||
|
||
bb0: { | ||
- _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1}); | ||
+ _0 = const false; | ||
return; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ test-mir-pass: GVN | ||
//@ compile-flags: -C opt-level=2 | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn generic<T>() {} | ||
|
||
const fn type_id_of_val<T: 'static>(_: &T) -> u128 { | ||
std::intrinsics::type_id::<T>() | ||
} | ||
|
||
// EMIT_MIR gvn_type_id_polymorphic.cursed_is_i32.GVN.diff | ||
fn cursed_is_i32<T: 'static>() -> bool { | ||
// CHECK-LABEL: fn cursed_is_i32( | ||
// CHECK: _0 = const false; | ||
// CHECK-NEXT: return; | ||
(const { type_id_of_val(&generic::<T>) } == const { type_id_of_val(&generic::<i32>) }) | ||
} | ||
|
||
fn main() { | ||
dbg!(cursed_is_i32::<i32>()); | ||
} |