Skip to content

Commit 31aeccc

Browse files
committed
Auto-upgrade data layouts for X86 address spaces
This is similar to the autoupdate LLVM performs internally.
1 parent c3ab84b commit 31aeccc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/librustc_codegen_llvm/context.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ 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) && 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+
146162
pub unsafe fn create_module(
147163
tcx: TyCtxt<'_>,
148164
llcx: &'ll llvm::Context,
@@ -156,6 +172,13 @@ pub unsafe fn create_module(
156172
if llvm_util::get_major_version() < 9 {
157173
target_data_layout = strip_function_ptr_alignment(target_data_layout);
158174
}
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+
}
159182

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

0 commit comments

Comments
 (0)