<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59012>59012</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Infinite recursion when attempting to print incomplete `std::vector` parameter
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aeubanks
      </td>
    </tr>
</table>

<pre>
    After [D134378](https://reviews.llvm.org/D134378), we started seeing crashes with incomplete types (in the
context of shared libraries).

When trying to print a `std::vector<int> &` with only debug info for a
declaration, we now try to use the formatter after [D134378](https://reviews.llvm.org/D134378). With an
incomplete type, this somehow goes into infinite recursion with the
frames

```
lldb_private::ValueObject::Dereference
lldb_private::ValueObjectSynthetic::CreateSynthFilter
lldb_private::ValueObjectSynthetic::ValueObjectSynthetic
lldb_private::ValueObject::CalculateSyntheticValue
lldb_private::ValueObject::HasSyntheticValue
```

The reason this only started appearing after [D134378](https://reviews.llvm.org/D134378) was because
previously with incomplete types, for names with `<`, lldb would attempt
to parse template parameter DIEs, which were empty, then create an empty
`ClassTemplateSpecializationDecl` which overrode the name used to lookup
a formatter in `FormattersMatchData()` to not include template
parameters (e.g. `std::vector<> &`). After [D134378](https://reviews.llvm.org/D134378) we don't create a
`ClassTemplateSpecializationDecl` when there are no template parameters
and the name to lookup a formatter is the original name (e.g.
`std::vector<int> &`).

The code to try harder with incomplete child compiler types was added in
[D79554](https://reviews.llvm.org/D79554) for ObjC purposes.
I'm not sure why this infinite recursion doesn't happen with ObjC (don't have a mac to test).

Repro:
```
$ cat /tmp/a.cc
#include <vector>

void f(std::vector<int>& v) {
        *(volatile int*) nullptr = 0;
}
$ cat /tmp/main.cc
#include <vector>

void f(std::vector<int>& v);

int main() {
        std::vector<int> v ;
        f(v);
}
$ ./build/bin/clang++ -g /tmp/a.cc -o /tmp/a.so -shared -stdlib=libc++ -fuse-ld=lld -Wl,-rpath,$PWD/build/lib
$ ./build/bin/clang++ -g /tmp/main.cc /tmp/a.so -o /tmp/a -stdlib=libc++ -fuse-ld=lld -Wl,-rpath,$PWD/build/lib
$ ./build/bin/lldb /tmp/a -b -o run
# crash
```

I've sent out https://reviews.llvm.org/D137983 to disable this automatic dereference of C++ types but of course a real fix would be better.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vk2T4jYQ_TXmooICG_Nx4DADQ2UPqaSyW5ljSpYFVlZYLkmGJb8-ryWbYQiTzGYqmfIY0Ef369fdTypMeV497Ly0LMkfN5Nsms0XSb5J0kXlfeOS7CFJt3isPCp5ciOtj4eRsXsM9avTZZKu2Uky57n1smROSlXvmbDcVdKxk_IVU7Uwh0ZLL5k_NxiFB1UzX8lkvEnGD8LUXn7zzOyYq7iFFa0Ky62SDg5GcVF8P1cSG-2ZfHjDGqtqzzhLZmPnSwKcPRyl8MYm2RpTSfYEZzNMRySm1mdWyqLdA9TOsJ2xjEfLpRSaW-6VqbuQanMiV-SndZLg0voD98QY_yhvI_ZMiHgd3d9wRBB8pRxz5iArANkb8IaIDAFXtcI6K0VrHfDG2C507iw_gLkr1hB_94SfWpfFb6DuyL2MnP3KdSt_Kn4HdXFgI63c4b8W8h17Pp9rePdKxJm1lVgVBrdKg6fvN3F35r3g11yLVvcQaGtY8u79P3B3b-cNi_H9paJEcGfqmK9QYX0z8KaRKGPU6ofLhZ24Y4UUHKUYPTe03rQO_u52GZUQ1XdN1RCXEPZsTW_MERHsZFoNnCjpQ-OjXWorbqngMUYs0k_YoAA2n56C3VOlRIUesZLRxnMsV7SmCKlHVXfjPXFrzZ370hn83EihuFZ_hG7boPFCgwab5iitNWVsN4JOvVdSD2pjvrZNtMivOhFKgu3b_rf7kXtRbbjnIJj0CaaxuzaeGNJt-RJYx2MfXdAlOdqP7svJi5aE7v2wcJLElCQ2c3-h7fv4kkFDkQNoJgK8k7BOBXhdvvB5oZK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