Skip to content

Commit 5c268cf

Browse files
authored
[Clang] Extend EmitPseudoVariable to support debug records (#94956)
CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly collect llvm.dbg.declare users of an alloca. This patch replaces this with an LLVM function for finding debug declares intrinsics and also adds the same for debug records, simplifying the code and adding record support. No tests added in this commit because it is NFC for intrinsics, and there is no way to make clang emit records directly yet - one of the existing tests however will switch to covering debug records once #89799 relands.
1 parent 8b7e836 commit 5c268cf

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

+10-22
Original file line numberDiff line numberDiff line change
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
57665766
// it is loaded upon use, so we identify such pattern here.
57675767
if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Value)) {
57685768
llvm::Value *Var = Load->getPointerOperand();
5769-
if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
5770-
if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
5771-
CGM.getLLVMContext(), MDValue)) {
5772-
for (llvm::User *U : DbgValue->users()) {
5773-
if (llvm::CallInst *DbgDeclare = dyn_cast<llvm::CallInst>(U)) {
5774-
if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
5775-
llvm::Intrinsic::dbg_declare &&
5776-
DbgDeclare->getArgOperand(0) == DbgValue) {
5777-
// There can be implicit type cast applied on a variable if it is
5778-
// an opaque ptr, in this case its debug info may not match the
5779-
// actual type of object being used as in the next instruction, so
5780-
// we will need to emit a pseudo variable for type-casted value.
5781-
llvm::DILocalVariable *MDNode = cast<llvm::DILocalVariable>(
5782-
cast<llvm::MetadataAsValue>(DbgDeclare->getOperand(1))
5783-
->getMetadata());
5784-
if (MDNode->getType() == Type)
5785-
return;
5786-
}
5787-
}
5788-
}
5789-
}
5790-
}
5769+
// There can be implicit type cast applied on a variable if it is an opaque
5770+
// ptr, in this case its debug info may not match the actual type of object
5771+
// being used as in the next instruction, so we will need to emit a pseudo
5772+
// variable for type-casted value.
5773+
auto DeclareTypeMatches = [&](auto *DbgDeclare) {
5774+
return DbgDeclare->getVariable()->getType() == Type;
5775+
};
5776+
if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
5777+
any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
5778+
return;
57915779
}
57925780

57935781
// Find the correct location to insert a sequence of instructions to

0 commit comments

Comments
 (0)