File tree 2 files changed +35
-5
lines changed
2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -191,11 +191,9 @@ impl<'mir, 'tcx> GlobalStateInner {
191
191
slack,
192
192
) ;
193
193
194
- // Remember next base address. Leave a gap of at least 1 to avoid two zero-sized allocations
195
- // having the same base address, and to avoid ambiguous provenance for the address between two
196
- // allocations (also see https://github.com/rust-lang/unsafe-code-guidelines/issues/313).
197
- let size_plus_1 = size. bytes ( ) . checked_add ( 1 ) . unwrap ( ) ;
198
- global_state. next_base_addr = base_addr. checked_add ( size_plus_1) . unwrap ( ) ;
194
+ // Remember next base address. We *do* allow allocations to touch each other,
195
+ // and ZST allocations to have the same address.
196
+ global_state. next_base_addr = base_addr. checked_add ( size. bytes ( ) ) . unwrap ( ) ;
199
197
// Given that `next_base_addr` increases in each allocation, pushing the
200
198
// corresponding tuple keeps `int_to_ptr_map` sorted
201
199
global_state. int_to_ptr_map . push ( ( base_addr, alloc_id) ) ;
Original file line number Diff line number Diff line change 1
1
// compile-flags: -Zmiri-permissive-provenance
2
2
3
+ fn ensure_allocs_can_be_adjacent ( ) {
4
+ for _ in 0 ..512 {
5
+ let n = 0u64 ;
6
+ let ptr: * const u64 = & n;
7
+ let ptr2 = {
8
+ let m = 0u64 ;
9
+ & m as * const u64
10
+ } ;
11
+ if ptr. wrapping_add ( 1 ) == ptr2 {
12
+ return
13
+ }
14
+ }
15
+ panic ! ( "never saw adjacent stack variables?" ) ;
16
+ }
17
+
18
+ fn ensure_zst_allocs_can_be_adjacent ( ) {
19
+ for _ in 0 ..512 {
20
+ let n = ( ) ;
21
+ let ptr: * const ( ) = & n;
22
+ let ptr2 = {
23
+ let m = ( ) ;
24
+ & m as * const ( )
25
+ } ;
26
+ if ptr == ptr2 {
27
+ return
28
+ }
29
+ }
30
+ panic ! ( "never saw adjacent zero-sized stack variables?" ) ;
31
+ }
32
+
3
33
fn test1 ( ) {
4
34
// The slack between allocations is random.
5
35
// Loop a few times to hit the zero-slack case.
@@ -42,6 +72,8 @@ fn test2() {
42
72
}
43
73
44
74
fn main ( ) {
75
+ ensure_allocs_can_be_adjacent ( ) ;
76
+ ensure_zst_allocs_can_be_adjacent ( ) ;
45
77
test1 ( ) ;
46
78
test2 ( ) ;
47
79
}
You can’t perform that action at this time.
0 commit comments