@@ -6,12 +6,12 @@ use rustc::ty::Instance;
6
6
use rustc:: ty:: ParamEnv ;
7
7
use rustc:: ty:: query:: TyCtxtAt ;
8
8
use rustc:: ty:: layout:: { self , Align , TargetDataLayout , Size } ;
9
- use syntax:: ast:: Mutability ;
10
-
11
- use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
12
9
use rustc:: mir:: interpret:: { Pointer , AllocId , Allocation , AccessKind , Value ,
13
10
EvalResult , Scalar , EvalErrorKind , GlobalId , AllocType } ;
14
11
pub use rustc:: mir:: interpret:: { write_target_uint, write_target_int, read_target_uint} ;
12
+ use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
13
+
14
+ use syntax:: ast:: Mutability ;
15
15
16
16
use super :: { EvalContext , Machine } ;
17
17
@@ -41,11 +41,6 @@ pub struct Memory<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
41
41
/// Actual memory allocations (arbitrary bytes, may contain pointers into other allocations).
42
42
alloc_map : FxHashMap < AllocId , Allocation > ,
43
43
44
- /// Actual memory allocations (arbitrary bytes, may contain pointers into other allocations).
45
- ///
46
- /// Stores statics while they are being processed, before they are interned and thus frozen
47
- uninitialized_statics : FxHashMap < AllocId , Allocation > ,
48
-
49
44
/// The current stack frame. Used to check accesses against locks.
50
45
pub cur_frame : usize ,
51
46
@@ -58,7 +53,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
58
53
data,
59
54
alloc_kind : FxHashMap :: default ( ) ,
60
55
alloc_map : FxHashMap :: default ( ) ,
61
- uninitialized_statics : FxHashMap :: default ( ) ,
62
56
tcx,
63
57
cur_frame : usize:: max_value ( ) ,
64
58
}
@@ -82,20 +76,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
82
76
pub fn allocate_value (
83
77
& mut self ,
84
78
alloc : Allocation ,
85
- kind : Option < MemoryKind < M :: MemoryKinds > > ,
79
+ kind : MemoryKind < M :: MemoryKinds > ,
86
80
) -> EvalResult < ' tcx , AllocId > {
87
81
let id = self . tcx . alloc_map . lock ( ) . reserve ( ) ;
88
82
M :: add_lock ( self , id) ;
89
- match kind {
90
- Some ( kind @ MemoryKind :: Stack ) |
91
- Some ( kind @ MemoryKind :: Machine ( _) ) => {
92
- self . alloc_map . insert ( id, alloc) ;
93
- self . alloc_kind . insert ( id, kind) ;
94
- } ,
95
- None => {
96
- self . uninitialized_statics . insert ( id, alloc) ;
97
- } ,
98
- }
83
+ self . alloc_map . insert ( id, alloc) ;
84
+ self . alloc_kind . insert ( id, kind) ;
99
85
Ok ( id)
100
86
}
101
87
@@ -104,7 +90,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
104
90
& mut self ,
105
91
size : Size ,
106
92
align : Align ,
107
- kind : Option < MemoryKind < M :: MemoryKinds > > ,
93
+ kind : MemoryKind < M :: MemoryKinds > ,
108
94
) -> EvalResult < ' tcx , Pointer > {
109
95
self . allocate_value ( Allocation :: undef ( size, align) , kind) . map ( Pointer :: from)
110
96
}
@@ -132,7 +118,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
132
118
}
133
119
134
120
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc"
135
- let new_ptr = self . allocate ( new_size, new_align, Some ( kind) ) ?;
121
+ let new_ptr = self . allocate ( new_size, new_align, kind) ?;
136
122
self . copy (
137
123
ptr. into ( ) ,
138
124
old_align,
@@ -168,12 +154,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
168
154
169
155
let alloc = match self . alloc_map . remove ( & ptr. alloc_id ) {
170
156
Some ( alloc) => alloc,
171
- None => if self . uninitialized_statics . contains_key ( & ptr. alloc_id ) {
172
- return err ! ( DeallocatedWrongMemoryKind (
173
- "uninitializedstatic" . to_string( ) ,
174
- format!( "{:?}" , kind) ,
175
- ) )
176
- } else {
157
+ None => {
177
158
return match self . tcx . alloc_map . lock ( ) . get ( ptr. alloc_id ) {
178
159
Some ( AllocType :: Function ( ..) ) => err ! ( DeallocatedWrongMemoryKind (
179
160
"function" . to_string( ) ,
@@ -299,24 +280,21 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
299
280
pub fn get ( & self , id : AllocId ) -> EvalResult < ' tcx , & Allocation > {
300
281
// normal alloc?
301
282
match self . alloc_map . get ( & id) {
302
- Some ( alloc) => Ok ( alloc) ,
283
+ Some ( alloc) => Ok ( alloc) ,
303
284
// uninitialized static alloc?
304
- None => match self . uninitialized_statics . get ( & id) {
305
- Some ( alloc) => Ok ( alloc) ,
306
- None => {
307
- // static alloc?
308
- let alloc = self . tcx . alloc_map . lock ( ) . get ( id) ;
309
- match alloc {
310
- Some ( AllocType :: Memory ( mem) ) => Ok ( mem) ,
311
- Some ( AllocType :: Function ( ..) ) => {
312
- Err ( EvalErrorKind :: DerefFunctionPointer . into ( ) )
313
- }
314
- Some ( AllocType :: Static ( did) ) => {
315
- self . const_eval_static ( did)
316
- }
317
- None => Err ( EvalErrorKind :: DanglingPointerDeref . into ( ) ) ,
285
+ None => {
286
+ // static alloc?
287
+ let alloc = self . tcx . alloc_map . lock ( ) . get ( id) ;
288
+ match alloc {
289
+ Some ( AllocType :: Memory ( mem) ) => Ok ( mem) ,
290
+ Some ( AllocType :: Function ( ..) ) => {
291
+ Err ( EvalErrorKind :: DerefFunctionPointer . into ( ) )
292
+ }
293
+ Some ( AllocType :: Static ( did) ) => {
294
+ self . const_eval_static ( did)
318
295
}
319
- } ,
296
+ None => Err ( EvalErrorKind :: DanglingPointerDeref . into ( ) ) ,
297
+ }
320
298
} ,
321
299
}
322
300
}
@@ -329,17 +307,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
329
307
match self . alloc_map . get_mut ( & id) {
330
308
Some ( alloc) => Ok ( alloc) ,
331
309
// uninitialized static alloc?
332
- None => match self . uninitialized_statics . get_mut ( & id) {
333
- Some ( alloc) => Ok ( alloc) ,
334
- None => {
335
- // no alloc or immutable alloc? produce an error
336
- match self . tcx . alloc_map . lock ( ) . get ( id) {
337
- Some ( AllocType :: Memory ( ..) ) |
338
- Some ( AllocType :: Static ( ..) ) => err ! ( ModifiedConstantMemory ) ,
339
- Some ( AllocType :: Function ( ..) ) => err ! ( DerefFunctionPointer ) ,
340
- None => err ! ( DanglingPointerDeref ) ,
341
- }
342
- } ,
310
+ None => {
311
+ // no alloc or immutable alloc? produce an error
312
+ match self . tcx . alloc_map . lock ( ) . get ( id) {
313
+ Some ( AllocType :: Memory ( ..) ) |
314
+ Some ( AllocType :: Static ( ..) ) => err ! ( ModifiedConstantMemory ) ,
315
+ Some ( AllocType :: Function ( ..) ) => err ! ( DerefFunctionPointer ) ,
316
+ None => err ! ( DanglingPointerDeref ) ,
317
+ }
343
318
} ,
344
319
}
345
320
}
@@ -390,27 +365,23 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
390
365
MemoryKind :: Stack => " (stack)" . to_owned ( ) ,
391
366
MemoryKind :: Machine ( m) => format ! ( " ({:?})" , m) ,
392
367
} ) ,
393
- // uninitialized static alloc?
394
- None => match self . uninitialized_statics . get ( & id) {
395
- Some ( a) => ( a, " (static in the process of initialization)" . to_owned ( ) ) ,
396
- None => {
397
- // static alloc?
398
- match self . tcx . alloc_map . lock ( ) . get ( id) {
399
- Some ( AllocType :: Memory ( a) ) => ( a, "(immutable)" . to_owned ( ) ) ,
400
- Some ( AllocType :: Function ( func) ) => {
401
- trace ! ( "{} {}" , msg, func) ;
402
- continue ;
403
- }
404
- Some ( AllocType :: Static ( did) ) => {
405
- trace ! ( "{} {:?}" , msg, did) ;
406
- continue ;
407
- }
408
- None => {
409
- trace ! ( "{} (deallocated)" , msg) ;
410
- continue ;
411
- }
368
+ None => {
369
+ // static alloc?
370
+ match self . tcx . alloc_map . lock ( ) . get ( id) {
371
+ Some ( AllocType :: Memory ( a) ) => ( a, "(immutable)" . to_owned ( ) ) ,
372
+ Some ( AllocType :: Function ( func) ) => {
373
+ trace ! ( "{} {}" , msg, func) ;
374
+ continue ;
412
375
}
413
- } ,
376
+ Some ( AllocType :: Static ( did) ) => {
377
+ trace ! ( "{} {:?}" , msg, did) ;
378
+ continue ;
379
+ }
380
+ None => {
381
+ trace ! ( "{} (deallocated)" , msg) ;
382
+ continue ;
383
+ }
384
+ }
414
385
} ,
415
386
} ;
416
387
@@ -569,8 +540,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
569
540
Some ( MemoryKind :: Machine ( _) ) => bug ! ( "machine didn't handle machine alloc" ) ,
570
541
Some ( MemoryKind :: Stack ) => { } ,
571
542
}
572
- let uninit = self . uninitialized_statics . remove ( & alloc_id) ;
573
- if let Some ( mut alloc) = alloc. or ( uninit) {
543
+ if let Some ( mut alloc) = alloc {
574
544
// ensure llvm knows not to put this into immutable memroy
575
545
alloc. runtime_mutability = mutability;
576
546
let alloc = self . tcx . intern_const_alloc ( alloc) ;
0 commit comments