Skip to content

Commit d607231

Browse files
committed
Auto merge of #69155 - chrissimpkins:llvm-globals, r=eddyb
Add support for LLVM globals corresponding to miri allocations should be named alloc123 Adds support for this request from @eddyb in #69134: > That is, if -Zfewer-names is false (usually only because of --emit=llvm-ir), we should use the same name for LLVM globals we generate out of miri allocs as #67133 does in MIR output (allocN). > >This way, we can easily see the mapping between MIR and LLVM IR (and it shouldn't be any costlier for regular compilation, which would continue to use unnamed globals). r? @eddyb cc @oli-obk
2 parents 54b7d21 + cf929f7 commit d607231

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/librustc_codegen_llvm/common.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,14 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
259259
let base_addr = match alloc_kind {
260260
Some(GlobalAlloc::Memory(alloc)) => {
261261
let init = const_alloc_to_llvm(self, alloc);
262-
if alloc.mutability == Mutability::Mut {
263-
self.static_addr_of_mut(init, alloc.align, None)
264-
} else {
265-
self.static_addr_of(init, alloc.align, None)
262+
let value = match alloc.mutability {
263+
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
264+
_ => self.static_addr_of(init, alloc.align, None),
265+
};
266+
if !self.sess().fewer_names() {
267+
llvm::set_value_name(value, format!("{:?}", ptr.alloc_id).as_bytes());
266268
}
269+
value
267270
}
268271
Some(GlobalAlloc::Function(fn_instance)) => self.get_fn_addr(fn_instance),
269272
Some(GlobalAlloc::Static(def_id)) => {

src/test/codegen/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// CHECK: @STATIC = {{.*}}, align 4
1111

1212
// This checks the constants from inline_enum_const
13-
// CHECK: @{{[0-9]+}} = {{.*}}, align 2
13+
// CHECK: @alloc5 = {{.*}}, align 2
1414

1515
// This checks the constants from {low,high}_align_const, they share the same
1616
// constant, but the alignment differs, so the higher one should be used
17-
// CHECK: [[LOW_HIGH:@[0-9]+]] = {{.*}} getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* @2, i32 0, i32 0, i32 0), {{.*}},
17+
// CHECK: [[LOW_HIGH:@[0-9]+]] = {{.*}} getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* @alloc15, i32 0, i32 0, i32 0), {{.*}}
1818

1919
#[derive(Copy, Clone)]
2020
// repr(i16) is required for the {low,high}_align_const test

src/test/codegen/remap_path_prefix/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod aux_mod;
1212
include!("aux_mod.rs");
1313

1414
// Here we check that the expansion of the file!() macro is mapped.
15-
// CHECK: @0 = private unnamed_addr constant <{ [34 x i8] }> <{ [34 x i8] c"/the/src/remap_path_prefix/main.rs" }>, align 1
15+
// CHECK: @alloc1 = private unnamed_addr constant <{ [34 x i8] }> <{ [34 x i8] c"/the/src/remap_path_prefix/main.rs" }>, align 1
1616
pub static FILE_PATH: &'static str = file!();
1717

1818
fn main() {

0 commit comments

Comments
 (0)