@@ -825,6 +825,7 @@ fn op_to_prop_const<'tcx>(
825
825
// If this constant has scalar ABI, return it as a `ConstValue::Scalar`.
826
826
if let Abi :: Scalar ( abi:: Scalar :: Initialized { .. } ) = op. layout . abi
827
827
&& let Ok ( scalar) = ecx. read_scalar ( op)
828
+ && scalar. try_to_int ( ) . is_ok ( )
828
829
{
829
830
return Some ( ConstValue :: Scalar ( scalar) ) ;
830
831
}
@@ -833,6 +834,14 @@ fn op_to_prop_const<'tcx>(
833
834
if let Either :: Left ( mplace) = op. as_mplace_or_imm ( )
834
835
&& let MemPlaceMeta :: None = mplace. meta ( )
835
836
{
837
+ let ( size, align) = ecx. size_and_align_of_mplace ( & mplace) . ok ( ) ??;
838
+
839
+ let alloc_ref = ecx. get_ptr_alloc ( mplace. ptr ( ) , size, align) . ok ( ) ??;
840
+ // Do not try interning a value that contains provenance.
841
+ if alloc_ref. has_provenance ( ) {
842
+ return None ;
843
+ }
844
+
836
845
intern_const_alloc_for_constprop ( ecx, & mplace) . ok ( ) ?;
837
846
let pointer = mplace. ptr ( ) . into_pointer_or_addr ( ) . ok ( ) ?;
838
847
let ( alloc_id, offset) = pointer. into_parts ( ) ;
@@ -846,7 +855,13 @@ fn op_to_prop_const<'tcx>(
846
855
// Everything failed: create a new allocation to hold the data.
847
856
let alloc_id =
848
857
ecx. intern_with_temp_alloc ( op. layout , |ecx, dest| ecx. copy_op ( op, dest, false ) ) . ok ( ) ?;
849
- Some ( ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } )
858
+ let value = ConstValue :: Indirect { alloc_id, offset : Size :: ZERO } ;
859
+
860
+ if !value. has_provenance ( * ecx. tcx , op. layout . size ) {
861
+ return Some ( value) ;
862
+ }
863
+
864
+ None
850
865
}
851
866
852
867
impl < ' tcx > VnState < ' _ , ' tcx > {
@@ -898,9 +913,7 @@ impl<'tcx> VnState<'_, 'tcx> {
898
913
899
914
// Check that we do not leak a pointer.
900
915
// Those pointers may lose part of their identity in codegen.
901
- if value. has_provenance ( self . tcx , op. layout . size ) {
902
- return None ;
903
- }
916
+ assert ! ( !value. has_provenance( self . tcx, op. layout. size) ) ;
904
917
905
918
let const_ = Const :: Val ( value, op. layout . ty ) ;
906
919
Some ( ConstOperand { span : rustc_span:: DUMMY_SP , user_ty : None , const_ } )
0 commit comments