mirror of
https://github.com/rust-lang/rust.git
synced 2026-01-25 07:48:44 +00:00
add test for const type_id misoptimization
This commit is contained in:
13
tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
Normal file
13
tests/mir-opt/gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
22
tests/mir-opt/gvn_type_id_polymorphic.rs
Normal file
22
tests/mir-opt/gvn_type_id_polymorphic.rs
Normal file
@@ -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>());
|
||||
}
|
||||
Reference in New Issue
Block a user