[clang] [clang][DebugInfo] Don't mark structured bindings as artificial (PR #100355)
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 24 17:33:10 PDT 2024
Michael137 wrote:
> It looks like this is working for all other kinds of structured binding because `EmitDeclare(BindingDecl*, ...)` emits a proper `DILocalVariable` for them. But it skips `BindingDecl`s that have a holding variable for some reason. Perhaps a cleaner approach would be to make it handle that case too, and leave the holding variables themselves as artificial?
Yea that would be ideal. I was thinking of doing this, but wasn't quite sure how to best re-architect the codegen for structured bindings to make this happen.
We currently emit debug-info for structured bindings in 2 steps. The [`DecompositionDecl` itself gets codegen'd first](https://github.com/llvm/llvm-project/blob/c6e69b041a7e6d18463f6cf684b10fd46a62c496/clang/lib/CodeGen/CGDecl.cpp#L165). Which is what calls into `CGDebugInfo::EmitDeclare(BindingDecl*, ...)`. This creates a debug-info entry for the unnamed decomposition pair. But then [`CodeGenFunction::EmitDecl` calls `EmitVarDecl` for each holding var](https://github.com/llvm/llvm-project/blob/c6e69b041a7e6d18463f6cf684b10fd46a62c496/clang/lib/CodeGen/CGDecl.cpp#L169). This then goes through various layers of codegen until we hit `CGDebugInfo::EmitDeclare(VarDecl*,...)`. Hence we bail out early in the case of tuple-like bindings in step 1, and defer to `CGDebugInfo::EmitDeclare(VarDecl*)` to emit debug-info for each individual holding var.
So at some point in the code-gen process we need to bail out early in the case of structured bindings. AFAICT we have two options:
1. Detect the fact that we're dealing with holding vars [before calling `CGDebugInfo::EmitDeclare(VarDecl*)` ](https://github.com/llvm/llvm-project/blob/c6e69b041a7e6d18463f6cf684b10fd46a62c496/clang/lib/CodeGen/CGDecl.cpp#L1680-L1682). And just emit all the debug-info for a decomposition in `CGDebugInfo::EmitDeclare(BindingDecl*, ...)`
2. OR, detect that we're emitting holding vars in `CGDebugInfo::EmitDeclare(BindingDecl*, ...)`, and emit the debug-info for them in `CGDebugInfo::EmitDeclare(VarDecl*, ...)`. Which is what the current patch is doing.
Any preferences here? Or maybe I'm missing a better approach
https://github.com/llvm/llvm-project/pull/100355
More information about the cfe-commits
mailing list