Skip to content

Commit 4898753

Browse files
author
Lukas Markeffsky
committed
add test for const type_id misoptimization
1 parent 4bb6ec0 commit 4898753

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- // MIR for `cursed_is_i32` before GVN
2+
+ // MIR for `cursed_is_i32` after GVN
3+
4+
fn cursed_is_i32() -> bool {
5+
let mut _0: bool;
6+
7+
bb0: {
8+
- _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1});
9+
+ _0 = const false;
10+
return;
11+
}
12+
}
13+
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ test-mir-pass: GVN
2+
//@ compile-flags: -C opt-level=2
3+
4+
#![feature(core_intrinsics)]
5+
6+
fn generic<T>() {}
7+
8+
const fn type_id_of_val<T: 'static>(_: &T) -> u128 {
9+
std::intrinsics::type_id::<T>()
10+
}
11+
12+
// EMIT_MIR gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
13+
fn cursed_is_i32<T: 'static>() -> bool {
14+
// CHECK-LABEL: fn cursed_is_i32(
15+
// CHECK: _0 = const false;
16+
// CHECK-NEXT: return;
17+
(const { type_id_of_val(&generic::<T>) } == const { type_id_of_val(&generic::<i32>) })
18+
}
19+
20+
fn main() {
21+
dbg!(cursed_is_i32::<i32>());
22+
}

0 commit comments

Comments
 (0)