@@ -1052,6 +1052,26 @@ fn remove_casts_must_change_both_sides(mut_a: &*mut u8, mut_b: *mut u8) -> bool
10521052 }
10531053}
10541054
1055+ /// Verify that we do not references to non-existing locals when dereferencing projections.
1056+ fn dereference_indexing ( array : [ u8 ; 2 ] , index : usize ) {
1057+ // CHECK-LABEL: fn dereference_indexing(
1058+ // CHECK: debug a => [[a:_.*]];
1059+ // CHECK: debug i => [[i:_.*]];
1060+
1061+ let a = {
1062+ // CHECK: [[i]] = Add(copy _2, const 1_usize);
1063+ let i = index + 1 ;
1064+ // CHECK: [[a]] = &_1[[[i]]];
1065+ & array[ i]
1066+ } ;
1067+
1068+ // CHECK-NOT: [{{.*}}]
1069+ // CHECK: [[tmp:_.*]] = copy (*[[a]]);
1070+ // CHECK: opaque::<u8>(move [[tmp]])
1071+ opaque ( * a) ;
1072+ }
1073+
1074+ // CHECK-LABEL: fn main(
10551075fn main ( ) {
10561076 subexpression_elimination ( 2 , 4 , 5 ) ;
10571077 wrap_unwrap ( 5 ) ;
@@ -1079,6 +1099,7 @@ fn main() {
10791099 slice_const_length ( & [ 1 ] ) ;
10801100 meta_of_ref_to_slice ( & 42 ) ;
10811101 slice_from_raw_parts_as_ptr ( & 123 , 456 ) ;
1102+ dereference_indexing ( [ 129 , 14 ] , 5 ) ;
10821103}
10831104
10841105#[ inline( never) ]
@@ -1138,3 +1159,4 @@ enum Never {}
11381159// EMIT_MIR gvn.cast_pointer_then_transmute.GVN.diff
11391160// EMIT_MIR gvn.transmute_then_cast_pointer.GVN.diff
11401161// EMIT_MIR gvn.remove_casts_must_change_both_sides.GVN.diff
1162+ // EMIT_MIR gvn.dereference_indexing.GVN.diff
0 commit comments