@@ -143,6 +143,22 @@ fn strip_function_ptr_alignment(data_layout: String) -> String {
143
143
data_layout. replace ( "-Fi8-" , "-" )
144
144
}
145
145
146
+ fn strip_x86_address_spaces ( data_layout : String ) -> String {
147
+ data_layout. replace ( "-p270:32:32-p271:32:32-p272:64:64-" , "-" )
148
+ }
149
+
150
+ fn add_x86_address_spaces ( mut data_layout : String ) -> String {
151
+ let address_spaces = "-p270:32:32-p271:32:32-p272:64:64" ;
152
+ if !data_layout. contains ( address_spaces) && data_layout. starts_with ( "e-m:" ) {
153
+ let mut insert_pos = "e-m:?" . len ( ) ;
154
+ if data_layout[ insert_pos..] . starts_with ( "-p:32:32" ) {
155
+ insert_pos += "-p:32:32" . len ( ) ;
156
+ }
157
+ data_layout. insert_str ( insert_pos, address_spaces) ;
158
+ }
159
+ data_layout
160
+ }
161
+
146
162
pub unsafe fn create_module (
147
163
tcx : TyCtxt < ' _ > ,
148
164
llcx : & ' ll llvm:: Context ,
@@ -156,6 +172,13 @@ pub unsafe fn create_module(
156
172
if llvm_util:: get_major_version ( ) < 9 {
157
173
target_data_layout = strip_function_ptr_alignment ( target_data_layout) ;
158
174
}
175
+ if sess. target . target . arch == "x86" || sess. target . target . arch == "x86_64" {
176
+ if llvm_util:: get_major_version ( ) < 10 {
177
+ target_data_layout = strip_x86_address_spaces ( target_data_layout) ;
178
+ } else {
179
+ target_data_layout = add_x86_address_spaces ( target_data_layout) ;
180
+ }
181
+ }
159
182
160
183
// Ensure the data-layout values hardcoded remain the defaults.
161
184
if sess. target . target . options . is_builtin {
0 commit comments