Skip to content

Commit

Permalink
Do not hash allocations to name them.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jan 7, 2024
1 parent 75c68cf commit cb6e396
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
9 changes: 0 additions & 9 deletions compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::value::Value;

use rustc_ast::Mutability;
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
use rustc_hir::def_id::DefId;
use rustc_middle::bug;
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
Expand Down Expand Up @@ -255,14 +254,6 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
_ => self.static_addr_of(init, alloc.align, None),
};
if !self.sess().fewer_names() && llvm::get_value_name(value).is_empty() {
let hash = self.tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
alloc.hash_stable(&mut hcx, &mut hasher);
hasher.finish::<Hash128>()
});
llvm::set_value_name(value, format!("alloc_{hash:032x}").as_bytes());
}
(value, AddressSpace::DATA)
}
GlobalAlloc::Function(fn_instance) => (
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
// CHECK: @STATIC = {{.*}}, align 4

// This checks the constants from inline_enum_const
// CHECK: @alloc_af1f8e8e6f4b341431a1d405e652df2d = {{.*}}, align 2
// CHECK: @0 = {{.*}}, align 2

// This checks the constants from {low,high}_align_const, they share the same
// constant, but the alignment differs, so the higher one should be used
// CHECK: [[LOW_HIGH:@alloc_[a-f0-9]+]] = {{.*}}, align 4
// CHECK: @1 = {{.*}}, align 4

#[derive(Copy, Clone)]
// repr(i16) is required for the {low,high}_align_const test
Expand Down Expand Up @@ -42,14 +42,14 @@ pub fn inline_enum_const() -> E<i8, i16> {
#[no_mangle]
pub fn low_align_const() -> E<i16, [i16; 3]> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: memcpy.{{.+}}(ptr align 2 %_0, ptr align 2 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
// CHECK: memcpy.{{.+}}(ptr align 2 %_0, ptr align 2 {{.*}}@1{{.*}}, i{{(32|64)}} 8, i1 false)
*&E::A(0)
}

// CHECK-LABEL: @high_align_const
#[no_mangle]
pub fn high_align_const() -> E<i16, i32> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}[[LOW_HIGH]]{{.*}}, i{{(32|64)}} 8, i1 false)
// CHECK: memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}@1{{.*}}, i{{(32|64)}} 8, i1 false)
*&E::A(0)
}
2 changes: 1 addition & 1 deletion tests/codegen/remap_path_prefix/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod aux_mod;
include!("aux_mod.rs");

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

fn main() {
Expand Down

0 comments on commit cb6e396

Please sign in to comment.