Skip to content

Commit

Permalink
Do not forget to pass DWARF fragment information to LLVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Aug 26, 2023
1 parent 25ed43d commit b3bbc22
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
18 changes: 16 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.store(place.llval, alloca.llval, alloca.align);

// Point the debug info to `*alloca` for the current variable
bx.dbg_var_addr(dbg_var, dbg_loc, alloca.llval, Size::ZERO, &[Size::ZERO], None);
bx.dbg_var_addr(
dbg_var,
dbg_loc,
alloca.llval,
Size::ZERO,
&[Size::ZERO],
var.fragment,
);
} else {
bx.dbg_var_addr(dbg_var, dbg_loc, base.llval, direct_offset, &indirect_offsets, None);
bx.dbg_var_addr(
dbg_var,
dbg_loc,
base.llval,
direct_offset,
&indirect_offsets,
var.fragment,
);
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/codegen/sroa-fragment-debuginfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// compile-flags: -g -Zmir-opt-level=0 -Zmir-enable-passes=+ScalarReplacementOfAggregates
// compile-flags: -Cno-prepopulate-passes

#![crate_type = "lib"]

pub struct Endian;

#[allow(dead_code)]
pub struct EndianSlice<'input> {
slice: &'input [u8],
endian: Endian,
}

#[no_mangle]
pub fn test(s: &[u8]) {
// CHECK: void @test(
// CHECK: %slice.dbg.spill1 = alloca { ptr, i64 },
// CHECK: %slice.dbg.spill = alloca %Endian,
// CHECK: %s.dbg.spill = alloca { ptr, i64 },
// CHECK: call void @llvm.dbg.declare(metadata ptr %s.dbg.spill, metadata ![[S:.*]], metadata !DIExpression()),
// CHECK: call void @llvm.dbg.declare(metadata ptr %slice.dbg.spill, metadata ![[SLICE:.*]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 0)),
// CHECK: call void @llvm.dbg.declare(metadata ptr %slice.dbg.spill1, metadata ![[SLICE]], metadata !DIExpression()),
let slice = EndianSlice { slice: s, endian: Endian };
}

// CHECK: ![[S]] = !DILocalVariable(name: "s",
// CHECK: ![[SLICE]] = !DILocalVariable(name: "slice",

0 comments on commit b3bbc22

Please sign in to comment.