Skip to content

Commit e14b34c

Browse files
committed
account for endianness in debuginfo for const args
1 parent 060acc9 commit e14b34c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,15 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
707707
hcx.while_hashing_spans(false, |hcx| ct.to_valtree().hash_stable(hcx, &mut hasher));
708708
// Let's only emit 64 bits of the hash value. That should be plenty for
709709
// avoiding collisions and will make the emitted type names shorter.
710-
let hash: u64 = hasher.finish();
710+
// Note: Don't use `StableHashResult` impl of `u64` here directly, since that
711+
// would lead to endianness problems.
712+
let hash: u128 = hasher.finish();
713+
let hash_short = (hash.to_le() as u64).to_le();
711714

712715
if cpp_like_debuginfo(tcx) {
713-
write!(output, "CONST${:x}", hash)
716+
write!(output, "CONST${:x}", hash_short)
714717
} else {
715-
write!(output, "{{CONST#{:x}}}", hash)
718+
write!(output, "{{CONST#{:x}}}", hash_short)
716719
}
717720
}
718721
},

src/test/debuginfo/function-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Const generic parameter
3838
// gdb-command:info functions -q function_names::const_generic_fn.*
3939
// gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
40-
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#3fcd7c34c1555be6}>();
40+
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#6348c650c7b26618}>();
4141
// gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
4242
// gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
4343

@@ -76,7 +76,7 @@
7676
// Const generic parameter
7777
// cdb-command:x a!function_names::const_generic_fn*
7878
// cdb-check:[...] a!function_names::const_generic_fn_bool<false> (void)
79-
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$3fcd7c34c1555be6> (void)
79+
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$6348c650c7b26618> (void)
8080
// cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void)
8181
// cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)
8282

0 commit comments

Comments
 (0)