Skip to content

[RemoveDIs] Update Clang front end to handle DbgRecords #84756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/CGBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,10 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
llvm::BasicBlock *resume = Builder.GetInsertBlock();

// Go back to the entry.
++entry_ptr;
if (entry_ptr->getNextNonDebugInstruction())
entry_ptr = entry_ptr->getNextNonDebugInstruction()->getIterator();
else
entry_ptr = entry->end();
Builder.SetInsertPoint(entry, entry_ptr);

// Emit debug information for all the DeclRefExprs.
Expand Down
22 changes: 17 additions & 5 deletions clang/lib/CodeGen/CGStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4746,20 +4746,32 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
(void)DI->EmitDeclareOfAutoVariable(SharedVar, ContextValue,
CGF.Builder, false);
llvm::Instruction &Last = CGF.Builder.GetInsertBlock()->back();
// Get the call dbg.declare instruction we just created and update
// its DIExpression to add offset to base address.
if (auto DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&Last)) {
auto UpdateExpr = [](llvm::LLVMContext &Ctx, auto *Declare,
unsigned Offset) {
SmallVector<uint64_t, 8> Ops;
// Add offset to the base address if non zero.
if (Offset) {
Ops.push_back(llvm::dwarf::DW_OP_plus_uconst);
Ops.push_back(Offset);
}
Ops.push_back(llvm::dwarf::DW_OP_deref);
auto &Ctx = DDI->getContext();
llvm::DIExpression *DIExpr = llvm::DIExpression::get(Ctx, Ops);
Last.setOperand(2, llvm::MetadataAsValue::get(Ctx, DIExpr));
Declare->setExpression(llvm::DIExpression::get(Ctx, Ops));
};
llvm::Instruction &Last = CGF.Builder.GetInsertBlock()->back();
if (auto DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&Last))
UpdateExpr(DDI->getContext(), DDI, Offset);
// If we're emitting using the new debug info format into a block
// without a terminator, the record will be "trailing".
assert(!Last.isTerminator() && "unexpected terminator");
if (auto *Marker =
CGF.Builder.GetInsertBlock()->getTrailingDPValues()) {
for (llvm::DPValue &DPV : llvm::reverse(
llvm::DPValue::filter(Marker->getDbgValueRange()))) {
UpdateExpr(Last.getContext(), &DPV, Offset);
break;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenObjC/debug-info-blocks.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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

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