Skip to content

Commit a913a2b

Browse files
committed
Name LLVM anonymous constants by a hash of their contents
1 parent 6ffabf3 commit a913a2b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/rustc_codegen_llvm/src/common.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::value::Value;
1010
use rustc_ast::Mutability;
1111
use rustc_codegen_ssa::mir::place::PlaceRef;
1212
use rustc_codegen_ssa::traits::*;
13+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1314
use rustc_hir::def_id::DefId;
1415
use rustc_middle::bug;
1516
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
@@ -252,8 +253,13 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
252253
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
253254
_ => self.static_addr_of(init, alloc.align, None),
254255
};
255-
if !self.sess().fewer_names() {
256-
llvm::set_value_name(value, format!("{:?}", alloc_id).as_bytes());
256+
if !self.sess().fewer_names() && llvm::get_value_name(value).is_empty() {
257+
let hash = self.tcx.with_stable_hashing_context(|mut hcx| {
258+
let mut hasher = StableHasher::new();
259+
alloc.hash_stable(&mut hcx, &mut hasher);
260+
hasher.finish::<u128>()
261+
});
262+
llvm::set_value_name(value, format!("alloc_{hash:032x}").as_bytes());
257263
}
258264
(value, AddressSpace::DATA)
259265
}

0 commit comments

Comments
 (0)