@@ -574,6 +574,29 @@ fn repeat() {
574
574
let array = [ val, val, val, val, val, val, val, val, val, val] ;
575
575
}
576
576
577
+ /// Verify that we do not merge fn pointers created by casts.
578
+ fn fn_pointers ( ) {
579
+ // CHECK-LABEL: fn fn_pointers(
580
+ // CHECK: [[f:_.*]] = identity::<u8> as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer
581
+ // CHECK: opaque::<fn(u8) -> u8>([[f]])
582
+ let f = identity as fn ( u8 ) -> u8 ;
583
+ opaque ( f) ;
584
+ // CHECK: [[g:_.*]] = identity::<u8> as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer
585
+ // CHECK: opaque::<fn(u8) -> u8>([[g]])
586
+ let g = identity as fn ( u8 ) -> u8 ;
587
+ opaque ( g) ;
588
+
589
+ // CHECK: [[cf:_.*]] = const {{.*}} as fn() (PointerCoercion(ClosureFnPointer
590
+ // CHECK: opaque::<fn()>([[cf]])
591
+ let closure = || { } ;
592
+ let cf = closure as fn ( ) ;
593
+ opaque ( cf) ;
594
+ // CHECK: [[cg:_.*]] = const {{.*}} as fn() (PointerCoercion(ClosureFnPointer
595
+ // CHECK: opaque::<fn()>([[cg]])
596
+ let cg = closure as fn ( ) ;
597
+ opaque ( cg) ;
598
+ }
599
+
577
600
fn main ( ) {
578
601
subexpression_elimination ( 2 , 4 , 5 ) ;
579
602
wrap_unwrap ( 5 ) ;
@@ -590,6 +613,7 @@ fn main() {
590
613
let ( direct, indirect) = duplicate_slice ( ) ;
591
614
assert_eq ! ( direct, indirect) ;
592
615
repeat ( ) ;
616
+ fn_pointers ( ) ;
593
617
}
594
618
595
619
#[ inline( never) ]
@@ -614,3 +638,4 @@ fn identity<T>(x: T) -> T {
614
638
// EMIT_MIR gvn.slices.GVN.diff
615
639
// EMIT_MIR gvn.duplicate_slice.GVN.diff
616
640
// EMIT_MIR gvn.repeat.GVN.diff
641
+ // EMIT_MIR gvn.fn_pointers.GVN.diff
0 commit comments