-
Notifications
You must be signed in to change notification settings - Fork 13.5k
DW_AT_artificial for structured bindings is incorrectly set #48909
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
Comments
Sure, sounds reasonable to me. Do you have a DWARF Consumer that's using the artificial attribute for anything? |
I just worked around this in the Fuchsia debugger: |
@llvm/issue-subscribers-debuginfo Author: None (llvmbot)
| | |
| --- | --- |
| Bugzilla Link | [49565](https://llvm.org/bz49565) |
| Version | trunk |
| OS | Linux |
| Attachments | [Test case](https://user-images.githubusercontent.com/60944935/143761896-ffd25b9a-11e8-4f33-be1d-e13e4a4b03f9.gz) |
| Reporter | LLVM Bugzilla Contributor |
| CC | @dwblaikie,@pogo59,@zygoloid |
Extended DescriptionWith structured bindings: auto [test_i, test_s] = GetTest(); Clang generates three variables in the DWARF symbols, one unnamed one for the std::pair returned from GetTest(), and then test_i and test_s. But test_i and test_s are marked as DW_AT_artifical even though they were user-declared, and the unnamed one is not, even though it was not user-declared:
This is backwards. The unnamed pair should be marked "artificial" while the two named variables in the structured bindings should not. GCC encodes the artificial tags in way I propose:
Fuchsia clang version 11.0.0 (https://fuchsia.googlesource.com/a/third_party/llvm-project 65f5887) |
Just a quick comment as this popped up in my notifications recently: Looks like this still reproduces, except that we don't emit the anonymous aggregate variable: https://godbolt.org/z/Mf734WG6E Curiously using a struct rather than std::pair doesn't reproduce it: https://godbolt.org/z/G3dzf6KPh |
Hmmm that seems like a regression we'd want to fix. In LLDB we got away with the
Now we wouldn't show anything (since LLDB by default hides artificial vars in the variable view):
Looks like this was explicitly changed in |
I guess there's an argument to be made that since the user can't reference the unnamed pair anyway, maybe LLDB should be smarter about what it shows in
This is because they're being handled in a different codepath. For the llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp Lines 4783 to 4784 in 0c4023a
Marking |
@llvm/issue-subscribers-clang-codegen Author: None (llvmbot)
| | |
| --- | --- |
| Bugzilla Link | [49565](https://llvm.org/bz49565) |
| Version | trunk |
| OS | Linux |
| Attachments | [Test case](https://user-images.githubusercontent.com/60944935/143761896-ffd25b9a-11e8-4f33-be1d-e13e4a4b03f9.gz) |
| Reporter | LLVM Bugzilla Contributor |
| CC | @dwblaikie,@pogo59,@zygoloid |
Extended DescriptionWith structured bindings: auto [test_i, test_s] = GetTest(); Clang generates three variables in the DWARF symbols, one unnamed one for the std::pair returned from GetTest(), and then test_i and test_s. But test_i and test_s are marked as DW_AT_artifical even though they were user-declared, and the unnamed one is not, even though it was not user-declared:
This is backwards. The unnamed pair should be marked "artificial" while the two named variables in the structured bindings should not. GCC encodes the artificial tags in way I propose:
Fuchsia clang version 11.0.0 (https://fuchsia.googlesource.com/a/third_party/llvm-project 65f5887) |
@AaronBallman Should we avoid setting the llvm-project/clang/lib/Sema/SemaDeclCXX.cpp Line 1319 in 0c4023a
Technically it doesn't contradict what
The more I think about it the more I lean towards the bindings shouldn't be |
What exists in the source is actually the So there's two things a debugger could expose: the names of the binding declarations and the value of the decomposition declaration. I would expect the binding names to show up in the debugger for sure, and I think users tend to think of them sort of like variables. The decomposition declaration is really only interesting in that it basically gives you the returned object from the initializer, so maybe that's also worth exposing. Now, whether this means you should avoid the Does that help? :-D |
I see, that makes sense. Thanks for clarifying! AFAICT there are two options to addressing the LLDB issue:
For (1), we currently mark anything that is
From your description of how the binding variables are introduced, in a very technical sense On the other hand, (2) would be the easier way to resolve this particular LLDB issue I suppose. |
A quick/rough estimate from me would be to do what gcc does. Both for consistency and because it feels like the right thing to me. As for how to implement it, again as a rough guess I'd want to label the variable non-artificial if the variables name was chosen by the user, but I'm not sure if/how to do that with clangs ast. I think it would be possible to check some property of the identifier info |
Not directly. It turns out that
but this might run into troubles for implicitly-generated code that provides valid source locations based on other user-provided tokens. |
) This patch is motivated by the debug-info issue in #48909. Clang is currently emitting the `DW_AT_artificial` attribute on debug-info entries for structured bindings whereas GCC does not. GCC's interpretation of the DWARF spec is more user-friendly in this regard, so we would like to do the same in Clang. [`CGDebugInfo` uses `isImplicit` to decide which variables to mark artificial](https://github.com/llvm/llvm-project/blob/0c4023ae3b64c54ff51947e9776aee0e963c5635/clang/lib/CodeGen/CGDebugInfo.cpp#L4783-L4784) (e.g., `ImplicitParamDecls`, compiler-generated variables, etc.). But for the purposes of debug-info, when we say "artificial", what we really mean in many cases is: "not explicitly spelled out in source". `VarDecl`s that back tuple-like bindings are [technically compiler-generated](#48909 (comment)), but that is a confusing notion for debug-info, since these bindings *are* spelled out in source. The [documentation for `isImplicit`](https://github.com/llvm/llvm-project/blob/68a0d0c76223736351fd7c452bca3ba9d80ca342/clang/include/clang/AST/DeclBase.h#L596-L600) does to some extent imply that implicit variables aren't written in source. This patch adds another condition to deciding whether a `VarDecl` should be marked artificial. Specifically, don't treat structured bindings as artificial. **Main alternatives considered** 1. Don't use `isImplicit` in `CGDebugInfo` when determining whether to add `DW_AT_artificial`. Instead use some other property of the AST that would tell us whether a node was explicitly spelled out in source or not * Considered using `SourceRange` or `SourceLocation` to tell us this, but didn't find a good way to, e.g., correctly identify that the implicit `this` parameter wasn't spelled out in source (as opposed to an unnamed parameter in a function declaration) 2. We could've also added a bit to `VarDeclBitFields` that indicates that a `VarDecl` is a holding var, but the use-case didn't feel like good enough justification for this 3. Don't set the `VarDecl` introduced as part of a tuple-like decomposition as implicit. * This may affect AST matching/traversal and this specific use-case wasn't enough to justify such a change Fixes #48909
Extended Description
With structured bindings:
auto [test_i, test_s] = GetTest();
Clang generates three variables in the DWARF symbols, one unnamed one for the std::pair returned from GetTest(), and then test_i and test_s. But test_i and test_s are marked as DW_AT_artifical even though they were user-declared, and the unnamed one is not, even though it was not user-declared:
This is backwards. The unnamed pair should be marked "artificial" while the two named variables in the structured bindings should not.
GCC encodes the artificial tags in way I propose:
Fuchsia clang version 11.0.0 (https://fuchsia.googlesource.com/a/third_party/llvm-project 65f5887)
The text was updated successfully, but these errors were encountered: