@@ -910,11 +910,13 @@ fn op_to_prop_const<'tcx>(
910
910
return Some ( ConstValue :: Scalar ( scalar) ) ;
911
911
}
912
912
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.
914
915
if let Either :: Left ( mplace) = op. as_mplace_or_imm ( ) {
915
916
let ( size, _align) = ecx. size_and_align_of_mplace ( & mplace) . ok ( ) ??;
916
917
917
918
// 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.
918
920
let alloc_ref = ecx. get_ptr_alloc ( mplace. ptr ( ) , size) . ok ( ) ??;
919
921
if alloc_ref. has_provenance ( ) {
920
922
return None ;
@@ -935,7 +937,10 @@ fn op_to_prop_const<'tcx>(
935
937
ecx. intern_with_temp_alloc ( op. layout , |ecx, dest| ecx. copy_op ( op, dest, false ) ) . ok ( ) ?;
936
938
let value = ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } ;
937
939
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 ) {
939
944
return Some ( value) ;
940
945
}
941
946
@@ -964,7 +969,8 @@ impl<'tcx> VnState<'_, 'tcx> {
964
969
965
970
// Check that we do not leak a pointer.
966
971
// 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) ) ;
968
974
969
975
let const_ = Const :: Val ( value, op. layout . ty ) ;
970
976
Some ( ConstOperand { span : rustc_span:: DUMMY_SP , user_ty : None , const_ } )
0 commit comments