diff options
| author | William Junda Huang <williamjhuang@google.com> | 2024-06-15 00:02:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-15 00:02:45 -0400 |
| commit | 675d8d629dbdc794a78d885511eacbabc7929f8a (patch) | |
| tree | 484bff08ff33591281b9603b16853ce858886532 /clang/lib/CodeGen/CGExprScalar.cpp | |
| parent | cddb9ce04e68d876de895d39d60b6af34d569012 (diff) | |
(New) Add option to generate additional debug info for expression dereferencing pointer to pointers (#95298)
This is a different implementation to #94100, which has been reverted.
When -fdebug-info-for-profiling is specified, for any Load expression if
the pointer operand is not a declared variable, clang will emit debug
info describing the type of the pointer operand (which can be an
intermediate expr)
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 1b144c178ce9..58f0a3113b4f 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1937,7 +1937,26 @@ Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) { } } - return EmitLoadOfLValue(E); + llvm::Value *Result = EmitLoadOfLValue(E); + + // If -fdebug-info-for-profiling is specified, emit a pseudo variable and its + // debug info for the pointer, even if there is no variable associated with + // the pointer's expression. + if (CGF.CGM.getCodeGenOpts().DebugInfoForProfiling && CGF.getDebugInfo()) { + if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Result)) { + if (llvm::GetElementPtrInst *GEP = + dyn_cast<llvm::GetElementPtrInst>(Load->getPointerOperand())) { + if (llvm::Instruction *Pointer = + dyn_cast<llvm::Instruction>(GEP->getPointerOperand())) { + QualType Ty = E->getBase()->getType(); + if (!E->isArrow()) + Ty = CGF.getContext().getPointerType(Ty); + CGF.getDebugInfo()->EmitPseudoVariable(Builder, Pointer, Ty); + } + } + } + } + return Result; } Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
