Skip to content

Commit 2de58b4

Browse files
authored
Rollup merge of rust-lang#136640 - Zalathar:debuginfo-align-bits, r=compiler-errors
Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit In rust-lang#116096, function ZSTs were made to have debuginfo that gives them an alignment of “1”. But because alignment in LLVM debuginfo is denoted in *bits*, not bytes, this resulted in an alignment specification of 1 bit instead of 1 byte. I don't know whether this has any practical consequences, but I noticed that a test started failing when I accidentally fixed the mistake while working on rust-lang#136632, so I extracted the fix (and the test adjustment) to this PR.
2 parents 64e06c0 + 4385a9e commit 2de58b4

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,16 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
319319
// This is actually a function pointer, so wrap it in pointer DI.
320320
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
321321
let (size, align) = match fn_ty.kind() {
322-
ty::FnDef(..) => (0, 1),
323-
ty::FnPtr(..) => (
324-
cx.tcx.data_layout.pointer_size.bits(),
325-
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
326-
),
322+
ty::FnDef(..) => (Size::ZERO, Align::ONE),
323+
ty::FnPtr(..) => (cx.tcx.data_layout.pointer_size, cx.tcx.data_layout.pointer_align.abi),
327324
_ => unreachable!(),
328325
};
329326
let di_node = unsafe {
330327
llvm::LLVMRustDIBuilderCreatePointerType(
331328
DIB(cx),
332329
fn_di_node,
333-
size,
334-
align,
330+
size.bits(),
331+
align.bits() as u32,
335332
0, // Ignore DWARF address space.
336333
name.as_c_char_ptr(),
337334
name.len(),

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
633633
true,
634634
DIFlags::FlagZero,
635635
argument_index,
636-
align.bytes() as u32,
636+
align.bits() as u32,
637637
)
638638
}
639639
}

tests/codegen/debug-fndef-size.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Verify that `i32::cmp` FnDef type is declared with size 0 and align 1 in LLVM debuginfo.
1+
// Verify that `i32::cmp` FnDef type is declared with a size of 0 and an
2+
// alignment of 8 bits (1 byte) in LLVM debuginfo.
3+
24
//@ compile-flags: -O -g -Cno-prepopulate-passes
35
//@ ignore-msvc the types are mangled differently
46

@@ -14,5 +16,5 @@ pub fn main() {
1416

1517
// CHECK: %compare.dbg.spill = alloca [0 x i8], align 1
1618
// CHECK: dbg{{.}}declare({{(metadata )?}}ptr %compare.dbg.spill, {{(metadata )?}}![[VAR:.*]], {{(metadata )?}}!DIExpression()
17-
// CHECK: ![[TYPE:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&i32, &i32) -> core::cmp::Ordering", baseType: !{{.*}}, align: 1, dwarfAddressSpace: {{.*}})
18-
// CHECK: ![[VAR]] = !DILocalVariable(name: "compare", scope: !{{.*}}, file: !{{.*}}, line: {{.*}}, type: ![[TYPE]], align: 1)
19+
// CHECK: ![[TYPE:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&i32, &i32) -> core::cmp::Ordering", baseType: !{{.*}}, align: 8, dwarfAddressSpace: {{.*}})
20+
// CHECK: ![[VAR]] = !DILocalVariable(name: "compare", scope: !{{.*}}, file: !{{.*}}, line: {{.*}}, type: ![[TYPE]], align: 8)

0 commit comments

Comments
 (0)