@@ -832,6 +832,7 @@ fn op_to_prop_const<'tcx>(
832
832
// If this constant has scalar ABI, return it as a `ConstValue::Scalar`.
833
833
if let Abi :: Scalar ( abi:: Scalar :: Initialized { .. } ) = op. layout . abi
834
834
&& let Ok ( scalar) = ecx. read_scalar ( op)
835
+ && scalar. try_to_int ( ) . is_ok ( )
835
836
{
836
837
return Some ( ConstValue :: Scalar ( scalar) ) ;
837
838
}
@@ -840,6 +841,14 @@ fn op_to_prop_const<'tcx>(
840
841
if let Either :: Left ( mplace) = op. as_mplace_or_imm ( )
841
842
&& let MemPlaceMeta :: None = mplace. meta ( )
842
843
{
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
+
843
852
intern_const_alloc_for_constprop ( ecx, & mplace) . ok ( ) ?;
844
853
let pointer = mplace. ptr ( ) . into_pointer_or_addr ( ) . ok ( ) ?;
845
854
let ( alloc_id, offset) = pointer. into_parts ( ) ;
@@ -853,7 +862,13 @@ fn op_to_prop_const<'tcx>(
853
862
// Everything failed: create a new allocation to hold the data.
854
863
let alloc_id =
855
864
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
857
872
}
858
873
859
874
impl < ' tcx > VnState < ' _ , ' tcx > {
@@ -905,9 +920,7 @@ impl<'tcx> VnState<'_, 'tcx> {
905
920
906
921
// Check that we do not leak a pointer.
907
922
// 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) ) ;
911
924
912
925
let const_ = Const :: Val ( value, op. layout . ty ) ;
913
926
Some ( ConstOperand { span : rustc_span:: DUMMY_SP , user_ty : None , const_ } )
0 commit comments