[clang] [clang] Dump Auto Type Inference (PR #95509)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 14 02:44:37 PDT 2024
https://github.com/Endilll commented:
Thank you for working on this, but I'm not sure this is the right direction.
The flag you're proposing is going to add unwieldy amount of remarks if used on a typical translation unit as opposed to a small example, because from what I understand, it dumps the type of every single `auto` in the TU. I believe this is bad ergonomics. You can improve it by not adding remarks to declarations in `#include`s, but this only gets you so far.
We already have more targeted means to achieve the same result, but they are reserved for the purpose of debugging Clang itself. I'm referring to `#pragma clang __debug dump` ([docs](https://clang.llvm.org/docs/LanguageExtensions.html#dump)):
```cpp
template <typename T>
T f(T) {
return {};
}
int main() {
auto a = f(0);
#pragma clang __debug dump a
}
```
yields (colorized in the actual terminal):
```
lookup results for a:
VarDecl 0xe93dce8 <<source>:7:3, col:15> col:8 a 'int' cinit
`-CallExpr 0xe93e108 <col:12, col:15> 'int'
|-ImplicitCastExpr 0xe93e0f0 <col:12> 'int (*)(int)' <FunctionToPointerDecay>
| `-DeclRefExpr 0xe93e060 <col:12> 'int (int)' lvalue Function 0xe93df60 'f' 'int (int)' (FunctionTemplate 0xe93d9e8 'f')
`-IntegerLiteral 0xe93dd98 <col:14> 'int' 0
```
https://godbolt.org/z/Ko5PqdvEh
If you're going to pursue this direction, having a pragma or an attribute that adds a remark to a particular declaration seems more useful by being less noisy.
> -mllvm -fdump-auto-type-inference
This patch adds frontend behavior, so it should be `-Xclang`, not `-mllvm`. But in any case, if we intend this to be a user interface, it should be a regular driver flag, not a frontend flag, because we shouldn't make promises to users about the latter.
https://github.com/llvm/llvm-project/pull/95509
More information about the cfe-commits
mailing list