@@ -749,14 +749,15 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
749
749
let contents = build_const_struct ( ccx, st, vals) ;
750
750
C_struct ( contents, st. packed )
751
751
}
752
- NullablePointer { nonnull : ref nonnull, nndiscr, ptrfield , .. } => {
752
+ NullablePointer { nonnull : ref nonnull, nndiscr, .. } => {
753
753
if discr == nndiscr {
754
754
C_struct ( build_const_struct ( ccx, nonnull, vals) , false )
755
755
} else {
756
- let vals = nonnull. fields . iter ( ) . enumerate ( ) . map ( |( i, & ty) | {
757
- let llty = type_of:: sizing_type_of ( ccx, ty) ;
758
- if i == ptrfield { C_null ( llty) } else { C_undef ( llty) }
759
- } ) . collect :: < ~[ ValueRef ] > ( ) ;
756
+ let vals = nonnull. fields . map ( |& ty| {
757
+ // Always use null even if it's not the `ptrfield`th
758
+ // field; see #8506.
759
+ C_null ( type_of:: sizing_type_of ( ccx, ty) )
760
+ } ) ;
760
761
C_struct ( build_const_struct ( ccx, nonnull, vals) , false )
761
762
}
762
763
}
@@ -791,14 +792,8 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
791
792
cfields. push ( padding ( target_offset - offset) ) ;
792
793
offset = target_offset;
793
794
}
794
- let val = if is_undef ( vals[ i] ) {
795
- let wrapped = C_struct ( [ vals[ i] ] , false ) ;
796
- assert ! ( !is_undef( wrapped) ) ;
797
- wrapped
798
- } else {
799
- vals[ i]
800
- } ;
801
- cfields. push ( val) ;
795
+ assert ! ( !is_undef( vals[ i] ) ) ;
796
+ cfields. push ( vals[ i] ) ;
802
797
offset += machine:: llsize_of_alloc ( ccx, llty) as u64
803
798
}
804
799
0 commit comments