@@ -24,11 +24,6 @@ pub enum MemPlaceMeta<Tag: Provenance = AllocId> {
2424 Meta ( Scalar < Tag > ) ,
2525 /// `Sized` types or unsized `extern type`
2626 None ,
27- /// The address of this place may not be taken. This protects the `MemPlace` from coming from
28- /// a ZST Operand without a backing allocation and being converted to an integer address. This
29- /// should be impossible, because you can't take the address of an operand, but this is a second
30- /// protection layer ensuring that we don't mess up.
31- Poison ,
3227}
3328
3429#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
@@ -38,15 +33,16 @@ impl<Tag: Provenance> MemPlaceMeta<Tag> {
3833 pub fn unwrap_meta ( self ) -> Scalar < Tag > {
3934 match self {
4035 Self :: Meta ( s) => s,
41- Self :: None | Self :: Poison => {
36+ Self :: None => {
4237 bug ! ( "expected wide pointer extra data (e.g. slice length or trait object vtable)" )
4338 }
4439 }
4540 }
41+
4642 pub fn has_meta ( self ) -> bool {
4743 match self {
4844 Self :: Meta ( _) => true ,
49- Self :: None | Self :: Poison => false ,
45+ Self :: None => false ,
5046 }
5147 }
5248}
@@ -163,10 +159,6 @@ impl<Tag: Provenance> MemPlace<Tag> {
163159 MemPlaceMeta :: Meta ( meta) => {
164160 Immediate :: ScalarPair ( Scalar :: from_maybe_pointer ( self . ptr , cx) . into ( ) , meta. into ( ) )
165161 }
166- MemPlaceMeta :: Poison => bug ! (
167- "MPlaceTy::dangling may never be used to produce a \
168- place that will have the address of its pointee taken"
169- ) ,
170162 }
171163 }
172164
@@ -195,13 +187,15 @@ impl<Tag: Provenance> Place<Tag> {
195187}
196188
197189impl < ' tcx , Tag : Provenance > MPlaceTy < ' tcx , Tag > {
198- /// Produces a MemPlace that works for ZST but nothing else
190+ /// Produces a MemPlace that works for ZST but nothing else.
191+ /// Conceptually this is a new allocation, but it doesn't actually create an allocation so you
192+ /// don't need to worry about memory leaks.
199193 #[ inline]
200- pub fn dangling ( layout : TyAndLayout < ' tcx > ) -> Self {
194+ pub fn fake_alloc_zst ( layout : TyAndLayout < ' tcx > ) -> Self {
195+ assert ! ( layout. is_zst( ) ) ;
201196 let align = layout. align . abi ;
202197 let ptr = Pointer :: from_addr ( align. bytes ( ) ) ; // no provenance, absolute address
203- // `Poison` this to make sure that the pointer value `ptr` is never observable by the program.
204- MPlaceTy { mplace : MemPlace { ptr, meta : MemPlaceMeta :: Poison } , layout, align }
198+ MPlaceTy { mplace : MemPlace { ptr, meta : MemPlaceMeta :: None } , layout, align }
205199 }
206200
207201 #[ inline]
@@ -273,7 +267,6 @@ impl<'tcx, Tag: Provenance> OpTy<'tcx, Tag> {
273267 Operand :: Indirect ( mplace) => {
274268 Ok ( MPlaceTy { mplace, layout : self . layout , align : self . align . unwrap ( ) } )
275269 }
276- Operand :: Immediate ( _) if self . layout . is_zst ( ) => Ok ( MPlaceTy :: dangling ( self . layout ) ) ,
277270 Operand :: Immediate ( imm) => Err ( ImmTy :: from_immediate ( imm, self . layout ) ) ,
278271 }
279272 }
0 commit comments