Skip to content

Commit

Permalink
Auto merge of #116096 - cjgillot:debuginfo-fndef-size, r=nikic
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Sep 24, 2023
2 parents 70a7fe1 + a49f7fe commit dbca215
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,20 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(

// This is actually a function pointer, so wrap it in pointer DI.
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
let (size, align) = match fn_ty.kind() {
ty::FnDef(..) => (0, 1),
ty::FnPtr(..) => (
cx.tcx.data_layout.pointer_size.bits(),
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
),
_ => unreachable!(),
};
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
fn_di_node,
cx.tcx.data_layout.pointer_size.bits(),
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
size,
align,
0, // Ignore DWARF address space.
name.as_ptr().cast(),
name.len(),
Expand Down
17 changes: 17 additions & 0 deletions tests/codegen/debug-fndef-size.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Verify that `i32::cmp` FnDef type is declared with size 0 and align 1 in LLVM debuginfo.
// compile-flags: -O -g -Cno-prepopulate-passes

use std::cmp::Ordering;

fn foo<F: FnOnce(&i32, &i32) -> Ordering>(v1: i32, v2: i32, compare: F) -> Ordering {
compare(&v1, &v2)
}

pub fn main() {
foo(0, 1, i32::cmp);
}

// CHECK: %compare.dbg.spill = alloca {}, align 1
// CHECK: call void @llvm.dbg.declare(metadata ptr %compare.dbg.spill, metadata ![[VAR:.*]], metadata !DIExpression()), !dbg !{{.*}}
// CHECK: ![[TYPE:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&i32, &i32) -> core::cmp::Ordering", baseType: !{{.*}}, align: 1, dwarfAddressSpace: {{.*}})
// CHECK: ![[VAR]] = !DILocalVariable(name: "compare", scope: !{{.*}}, file: !{{.*}}, line: {{.*}}, type: ![[TYPE]], align: 1)

0 comments on commit dbca215

Please sign in to comment.