Skip to content

Commit bfedf38

Browse files
committed
Auto-upgrade data layouts for X86 address spaces
1 parent f4ecb70 commit bfedf38

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/librustc_codegen_llvm/context.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ fn strip_function_ptr_alignment(data_layout: String) -> String {
143143
data_layout.replace("-Fi8-", "-")
144144
}
145145

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) {
153+
data_layout.insert_str("e-m:X".len(), address_spaces);
154+
}
155+
data_layout
156+
}
157+
146158
pub unsafe fn create_module(
147159
tcx: TyCtxt<'_>,
148160
llcx: &'ll llvm::Context,
@@ -156,6 +168,13 @@ pub unsafe fn create_module(
156168
if llvm_util::get_major_version() < 9 {
157169
target_data_layout = strip_function_ptr_alignment(target_data_layout);
158170
}
171+
if sess.target.target.arch == "x86" || sess.target.target.arch == "x86_64" {
172+
if llvm_util::get_major_version() < 10 {
173+
target_data_layout = strip_x86_address_spaces(target_data_layout);
174+
} else {
175+
target_data_layout = add_x86_address_spaces(target_data_layout);
176+
}
177+
}
159178

160179
// Ensure the data-layout values hardcoded remain the defaults.
161180
if sess.target.target.options.is_builtin {

0 commit comments

Comments
 (0)