@@ -832,6 +832,7 @@ fn op_to_prop_const<'tcx>(
832832 // If this constant has scalar ABI, return it as a `ConstValue::Scalar`.
833833 if let Abi :: Scalar ( abi:: Scalar :: Initialized { .. } ) = op. layout . abi
834834 && let Ok ( scalar) = ecx. read_scalar ( op)
835+ && scalar. try_to_int ( ) . is_ok ( )
835836 {
836837 return Some ( ConstValue :: Scalar ( scalar) ) ;
837838 }
@@ -840,6 +841,14 @@ fn op_to_prop_const<'tcx>(
840841 if let Either :: Left ( mplace) = op. as_mplace_or_imm ( )
841842 && let MemPlaceMeta :: None = mplace. meta ( )
842843 {
844+ let ( size, align) = ecx. size_and_align_of_mplace ( & mplace) . ok ( ) ??;
845+
846+ let alloc_ref = ecx. get_ptr_alloc ( mplace. ptr ( ) , size, align) . ok ( ) ??;
847+ // Do not try interning a value that contains provenance.
848+ if alloc_ref. has_provenance ( ) {
849+ return None ;
850+ }
851+
843852 intern_const_alloc_for_constprop ( ecx, & mplace) . ok ( ) ?;
844853 let pointer = mplace. ptr ( ) . into_pointer_or_addr ( ) . ok ( ) ?;
845854 let ( alloc_id, offset) = pointer. into_parts ( ) ;
@@ -853,7 +862,13 @@ fn op_to_prop_const<'tcx>(
853862 // Everything failed: create a new allocation to hold the data.
854863 let alloc_id =
855864 ecx. intern_with_temp_alloc ( op. layout , |ecx, dest| ecx. copy_op ( op, dest, false ) ) . ok ( ) ?;
856- Some ( ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } )
865+ let value = ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } ;
866+
867+ if !value. has_provenance ( * ecx. tcx , op. layout . size ) {
868+ return Some ( value) ;
869+ }
870+
871+ None
857872}
858873
859874impl < ' tcx > VnState < ' _ , ' tcx > {
@@ -905,9 +920,7 @@ impl<'tcx> VnState<'_, 'tcx> {
905920
906921 // Check that we do not leak a pointer.
907922 // Those pointers may lose part of their identity in codegen.
908- if value. has_provenance ( self . tcx , op. layout . size ) {
909- return None ;
910- }
923+ assert ! ( !value. has_provenance( self . tcx, op. layout. size) ) ;
911924
912925 let const_ = Const :: Val ( value, op. layout . ty ) ;
913926 Some ( ConstOperand { span : rustc_span:: DUMMY_SP , user_ty : None , const_ } )
0 commit comments