Skip to content

Commit 3e6db60

Browse files
committed
[RemoveDIs] Update Clang front end to handle DbgRecords (#84756)
This patch fixes problems that pop up when clang emits DbgRecords instead of debug intrinsics. Note: this doesn't mean clang is emitting DbgRecords yet, because the modules it creates are still always in the old debug mode. That will come in a future patch. Depends on #84739
1 parent 59f34e8 commit 3e6db60

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,10 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
15401540
llvm::BasicBlock *resume = Builder.GetInsertBlock();
15411541

15421542
// Go back to the entry.
1543-
++entry_ptr;
1543+
if (entry_ptr->getNextNonDebugInstruction())
1544+
entry_ptr = entry_ptr->getNextNonDebugInstruction()->getIterator();
1545+
else
1546+
entry_ptr = entry->end();
15441547
Builder.SetInsertPoint(entry, entry_ptr);
15451548

15461549
// Emit debug information for all the DeclRefExprs.

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,20 +4749,32 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
47494749
if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
47504750
(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
47514751
CGF.Builder, false);
4752-
llvm::Instruction &Last = CGF.Builder.GetInsertBlock()->back();
47534752
// Get the call dbg.declare instruction we just created and update
47544753
// its DIExpression to add offset to base address.
4755-
if (auto DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&Last)) {
4754+
auto UpdateExpr = [](llvm::LLVMContext &Ctx, auto *Declare,
4755+
unsigned Offset) {
47564756
SmallVector<uint64_t, 8> Ops;
47574757
// Add offset to the base address if non zero.
47584758
if (Offset) {
47594759
Ops.push_back(llvm::dwarf::DW_OP_plus_uconst);
47604760
Ops.push_back(Offset);
47614761
}
47624762
Ops.push_back(llvm::dwarf::DW_OP_deref);
4763-
auto &Ctx = DDI->getContext();
4764-
llvm::DIExpression *DIExpr = llvm::DIExpression::get(Ctx, Ops);
4765-
Last.setOperand(2, llvm::MetadataAsValue::get(Ctx, DIExpr));
4763+
Declare->setExpression(llvm::DIExpression::get(Ctx, Ops));
4764+
};
4765+
llvm::Instruction &Last = CGF.Builder.GetInsertBlock()->back();
4766+
if (auto DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&Last))
4767+
UpdateExpr(DDI->getContext(), DDI, Offset);
4768+
// If we're emitting using the new debug info format into a block
4769+
// without a terminator, the record will be "trailing".
4770+
assert(!Last.isTerminator() && "unexpected terminator");
4771+
if (auto *Marker =
4772+
CGF.Builder.GetInsertBlock()->getTrailingDbgRecords()) {
4773+
for (llvm::DPValue &DPV : llvm::reverse(
4774+
llvm::filterDbgVars(Marker->getDbgRecordRange()))) {
4775+
UpdateExpr(Last.getContext(), &DPV, Offset);
4776+
break;
4777+
}
47664778
}
47674779
}
47684780
}

clang/test/CodeGenObjC/debug-info-blocks.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
// CHECK: define {{.*}}_block_invoke
77
// CHECK: store ptr %.block_descriptor, ptr %[[ALLOCA:block.addr]], align
8-
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
98
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
9+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
1010

1111
// Test that we do emit scope info for the helper functions, and that the
1212
// parameters to these functions are marked as artificial (so the debugger

0 commit comments

Comments
 (0)