Skip to content

Commit c72d4de

Browse files
committed
Revert "[Clang] Extend EmitPseudoVariable to support debug records (llvm#94956)"
This reverts commit 5c268cf.
1 parent c6ee562 commit c72d4de

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5766,16 +5766,28 @@ 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-
// 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;
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+
}
57795791
}
57805792

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

0 commit comments

Comments
 (0)