1
1
use crate :: prelude:: * ;
2
2
3
+ use rustc_target:: abi:: Align ;
4
+
3
5
use cranelift_codegen:: ir:: immediates:: Offset32 ;
4
6
5
7
#[ derive( Copy , Clone , Debug ) ]
@@ -12,6 +14,7 @@ pub(crate) struct Pointer {
12
14
pub ( crate ) enum PointerBase {
13
15
Addr ( Value ) ,
14
16
Stack ( StackSlot ) ,
17
+ Dangling ( Align ) ,
15
18
}
16
19
17
20
impl Pointer {
@@ -37,6 +40,13 @@ impl Pointer {
37
40
}
38
41
}
39
42
43
+ pub ( crate ) fn dangling ( align : Align ) -> Self {
44
+ Pointer {
45
+ base : PointerBase :: Dangling ( align) ,
46
+ offset : Offset32 :: new ( 0 ) ,
47
+ }
48
+ }
49
+
40
50
#[ cfg( debug_assertions) ]
41
51
pub ( crate ) fn base_and_offset ( self ) -> ( PointerBase , Offset32 ) {
42
52
( self . base , self . offset )
@@ -53,6 +63,9 @@ impl Pointer {
53
63
}
54
64
}
55
65
PointerBase :: Stack ( stack_slot) => fx. bcx . ins ( ) . stack_addr ( fx. pointer_type , stack_slot, self . offset ) ,
66
+ PointerBase :: Dangling ( align) => {
67
+ fx. bcx . ins ( ) . iconst ( fx. pointer_type , i64:: try_from ( align. bytes ( ) ) . unwrap ( ) )
68
+ }
56
69
}
57
70
}
58
71
@@ -80,6 +93,7 @@ impl Pointer {
80
93
let base_addr = match self . base {
81
94
PointerBase :: Addr ( addr) => addr,
82
95
PointerBase :: Stack ( stack_slot) => fx. bcx . ins ( ) . stack_addr ( fx. pointer_type , stack_slot, 0 ) ,
96
+ PointerBase :: Dangling ( align) => fx. bcx . ins ( ) . iconst ( fx. pointer_type , i64:: try_from ( align. bytes ( ) ) . unwrap ( ) ) ,
83
97
} ;
84
98
let addr = fx. bcx . ins ( ) . iadd_imm ( base_addr, new_offset) ;
85
99
Pointer {
@@ -109,6 +123,13 @@ impl Pointer {
109
123
offset : Offset32 :: new ( 0 ) ,
110
124
}
111
125
}
126
+ PointerBase :: Dangling ( align) => {
127
+ let addr = fx. bcx . ins ( ) . iconst ( fx. pointer_type , i64:: try_from ( align. bytes ( ) ) . unwrap ( ) ) ;
128
+ Pointer {
129
+ base : PointerBase :: Addr ( fx. bcx . ins ( ) . iadd ( addr, extra_offset) ) ,
130
+ offset : self . offset ,
131
+ }
132
+ }
112
133
}
113
134
}
114
135
@@ -127,6 +148,7 @@ impl Pointer {
127
148
} else {
128
149
fx. bcx . ins ( ) . stack_load ( ty, stack_slot, self . offset )
129
150
}
151
+ PointerBase :: Dangling ( _align) => unreachable ! ( ) ,
130
152
}
131
153
}
132
154
@@ -150,6 +172,7 @@ impl Pointer {
150
172
fx. bcx . ins ( ) . stack_store ( value, stack_slot, self . offset ) ;
151
173
}
152
174
}
175
+ PointerBase :: Dangling ( _align) => unreachable ! ( ) ,
153
176
}
154
177
}
155
178
}
0 commit comments