Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a49f7fe

Browse files
committedSep 18, 2023
Make FnDef 1-ZST in LLVM debuginfo.
1 parent 8ed1d4a commit a49f7fe

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
 

‎compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,20 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
335335

336336
// This is actually a function pointer, so wrap it in pointer DI.
337337
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
338+
let (size, align) = match fn_ty.kind() {
339+
ty::FnDef(..) => (0, 1),
340+
ty::FnPtr(..) => (
341+
cx.tcx.data_layout.pointer_size.bits(),
342+
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
343+
),
344+
_ => unreachable!(),
345+
};
338346
let di_node = unsafe {
339347
llvm::LLVMRustDIBuilderCreatePointerType(
340348
DIB(cx),
341349
fn_di_node,
342-
cx.tcx.data_layout.pointer_size.bits(),
343-
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
350+
size,
351+
align,
344352
0, // Ignore DWARF address space.
345353
name.as_ptr().cast(),
346354
name.len(),

‎tests/codegen/debug-fndef-size.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Verify that `i32::cmp` FnDef type is declared with size 0 and align 1 in LLVM debuginfo.
2+
// compile-flags: -O -g -Cno-prepopulate-passes
3+
4+
use std::cmp::Ordering;
5+
6+
fn foo<F: FnOnce(&i32, &i32) -> Ordering>(v1: i32, v2: i32, compare: F) -> Ordering {
7+
compare(&v1, &v2)
8+
}
9+
10+
pub fn main() {
11+
foo(0, 1, i32::cmp);
12+
}
13+
14+
// CHECK: %compare.dbg.spill = alloca {}, align 1
15+
// CHECK: call void @llvm.dbg.declare(metadata ptr %compare.dbg.spill, metadata ![[VAR:.*]], metadata !DIExpression()), !dbg !{{.*}}
16+
// CHECK: ![[TYPE:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&i32, &i32) -> core::cmp::Ordering", baseType: !{{.*}}, align: 1, dwarfAddressSpace: {{.*}})
17+
// CHECK: ![[VAR]] = !DILocalVariable(name: "compare", scope: !{{.*}}, file: !{{.*}}, line: {{.*}}, type: ![[TYPE]], align: 1)

0 commit comments

Comments
 (0)
Failed to load comments.