@@ -910,11 +910,13 @@ fn op_to_prop_const<'tcx>(
910910 return Some ( ConstValue :: Scalar ( scalar) ) ;
911911 }
912912
913- // If this constant is a projection of another, we can return it directly.
913+ // If this constant is already represented as an `Allocation`,
914+ // try putting it into global memory to return it.
914915 if let Either :: Left ( mplace) = op. as_mplace_or_imm ( ) {
915916 let ( size, _align) = ecx. size_and_align_of_mplace ( & mplace) . ok ( ) ??;
916917
917918 // Do not try interning a value that contains provenance.
919+ // Due to https://github.com/rust-lang/rust/issues/79738, doing so could lead to bugs.
918920 let alloc_ref = ecx. get_ptr_alloc ( mplace. ptr ( ) , size) . ok ( ) ??;
919921 if alloc_ref. has_provenance ( ) {
920922 return None ;
@@ -935,7 +937,10 @@ fn op_to_prop_const<'tcx>(
935937 ecx. intern_with_temp_alloc ( op. layout , |ecx, dest| ecx. copy_op ( op, dest, false ) ) . ok ( ) ?;
936938 let value = ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } ;
937939
938- if !value. has_provenance ( * ecx. tcx , op. layout . size ) {
940+ // Check that we do not leak a pointer.
941+ // Those pointers may lose part of their identity in codegen.
942+ // See https://github.com/rust-lang/rust/issues/79738.
943+ if !value. may_have_provenance ( * ecx. tcx , op. layout . size ) {
939944 return Some ( value) ;
940945 }
941946
@@ -964,7 +969,8 @@ impl<'tcx> VnState<'_, 'tcx> {
964969
965970 // Check that we do not leak a pointer.
966971 // Those pointers may lose part of their identity in codegen.
967- assert ! ( !value. has_provenance( self . tcx, op. layout. size) ) ;
972+ // See https://github.com/rust-lang/rust/issues/79738.
973+ assert ! ( !value. may_have_provenance( self . tcx, op. layout. size) ) ;
968974
969975 let const_ = Const :: Val ( value, op. layout . ty ) ;
970976 Some ( ConstOperand { span : rustc_span:: DUMMY_SP , user_ty : None , const_ } )
0 commit comments