@@ -24,11 +24,6 @@ pub enum MemPlaceMeta<Tag: Provenance = AllocId> {
24
24
Meta ( Scalar < Tag > ) ,
25
25
/// `Sized` types or unsized `extern type`
26
26
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 ,
32
27
}
33
28
34
29
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
@@ -38,15 +33,16 @@ impl<Tag: Provenance> MemPlaceMeta<Tag> {
38
33
pub fn unwrap_meta ( self ) -> Scalar < Tag > {
39
34
match self {
40
35
Self :: Meta ( s) => s,
41
- Self :: None | Self :: Poison => {
36
+ Self :: None => {
42
37
bug ! ( "expected wide pointer extra data (e.g. slice length or trait object vtable)" )
43
38
}
44
39
}
45
40
}
41
+
46
42
pub fn has_meta ( self ) -> bool {
47
43
match self {
48
44
Self :: Meta ( _) => true ,
49
- Self :: None | Self :: Poison => false ,
45
+ Self :: None => false ,
50
46
}
51
47
}
52
48
}
@@ -163,10 +159,6 @@ impl<Tag: Provenance> MemPlace<Tag> {
163
159
MemPlaceMeta :: Meta ( meta) => {
164
160
Immediate :: ScalarPair ( Scalar :: from_maybe_pointer ( self . ptr , cx) . into ( ) , meta. into ( ) )
165
161
}
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
- ) ,
170
162
}
171
163
}
172
164
@@ -195,13 +187,15 @@ impl<Tag: Provenance> Place<Tag> {
195
187
}
196
188
197
189
impl < ' 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.
199
193
#[ inline]
200
- pub fn dangling ( layout : TyAndLayout < ' tcx > ) -> Self {
194
+ pub fn fake_alloc_zst ( layout : TyAndLayout < ' tcx > ) -> Self {
195
+ assert ! ( layout. is_zst( ) ) ;
201
196
let align = layout. align . abi ;
202
197
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 }
205
199
}
206
200
207
201
#[ inline]
@@ -273,7 +267,6 @@ impl<'tcx, Tag: Provenance> OpTy<'tcx, Tag> {
273
267
Operand :: Indirect ( mplace) => {
274
268
Ok ( MPlaceTy { mplace, layout : self . layout , align : self . align . unwrap ( ) } )
275
269
}
276
- Operand :: Immediate ( _) if self . layout . is_zst ( ) => Ok ( MPlaceTy :: dangling ( self . layout ) ) ,
277
270
Operand :: Immediate ( imm) => Err ( ImmTy :: from_immediate ( imm, self . layout ) ) ,
278
271
}
279
272
}
0 commit comments