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

    <tr>
        <th>Summary</th>
        <td>
            LLDB considers two distinct internal-linkage template specializations to refer to the same type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb
      </td>
    </tr>

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

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

<pre>
    x.h
```
template<typename T>
struct t2 {
  T v1;
};
```
a.cpp
```
#include "x.h"
namespace {
struct t1 {
  int v;
};
}
t2<t1> v2 = {42};
void *f1() {
  return &v2;
}
```
b.cpp
```
#include "x.h"
namespace {
struct t1 {
  float v;
};
}
t2<t1> v1 = {3.14};
void *f2() {
  return &v1;
}
int main() {
}
```

```
$ lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/usr/local/google/home/blaikie/dev/scratch/a.out' (x86_64).
(lldb) p v1
(t2<t1>) $0 = {
  v1 = (v = 3.1400001)
}
(lldb) p v2
(t2<t1>) $1 = {
  v1 = (v = 5.88545355E-44)
}
$ gdb ./a.out
...
(gdb) p v1
$1 = {
  v1 = {
    v = 3.1400001
  }
}
(gdb) p v2
$2 = {
  v1 = {
    v = 42
  }
}
(gdb) 
```

[this logic](https://github.com/llvm/llvm-project/blob/36c01876d79dd962d3aa1f5691dbd3faa437b9a8/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp#L46) only kicks in for types in anonymous namespaces (conversely, there are probably cases of anonymous types that /should/ be considered the same type - if such a type appears within a linkage-having type or function) - but there are other internal-linkage types that don't appear in anonymous namespaces: Templates instantiated on internal linkage types. In theory LLDB could search through the types of all the template parameters to check this (this would have to be a deep search, eg: the template type parameter might be a function pointer where one of the parameter types had internal linkage - arbitrarily deep/complicated to check) - internal linkage /variable/ non-type-template parameters might be harder, since they aren't connected in the DWARF, all you get is a name.

I started a thread on dwarf-workgroup http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2022-June/004920.html to discuss how this sort of thing should be represented, as it may be best to solve this with new DWARF encoding (have the compiler explicitly tell the consumer, in the DWARF, which types are local and which are not)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vk1z2zYQ_TXUBSMOCVKUeNDBieOZdHLoNO702AGBFYkaIlgAlKL--u6ClCVbdpoc6pFFEB-7b9--Xaix6rT9lnZJdp9kd0mVzZ_4GmA_GBEgKT6G0wC92AN7TIpP06oPbpSBBc6S9YdpirFHdsiTYn5N1veX8UvTIpXD8OZKwgvdSzMqYAnnBI3zaYX8-0FIuDg8Y8ivMeg-sMPbIHA8RcYpJkT6iR0Qf3FP50t-vfdgtUIEd7s84ZuE19ceHITR9bhaHfit8VcBNf9jqDtjxU8Fm5-DLdK8fDNc_t1w81vzRPde6P71uff4eIeKkhmjGpYm_EGkdgzn-Q1Nk-EgXAuBSQcoSSLssvVM28fROUA48A3kGERjgHk8EixuX-Pu0Tv8NlYKg8_W2tYADjq7p0djhH7SNFJwwG8vnQiyu3hZo5nNt031Z1UioPQG4UDiP09eWI-s8DI7U3-m9ZwMvjnEAaUkwz8UXP2awhdO-PtO8v9ysko3m1W5KlarT8uyfMtTydrbPKTpJdz2Ntr3_V5mcO5VmPPCxfdVuO1ttCX_cScl_xHr39Pn6kPotGfGtlomq3s81IUw-KTA8w-kHh26EWvb7klS5nB-LAdn_wIZoqAsunkoKpnlm3Wl1rVSdcVVIUS-W1V1rhpV7IQoi3VTi000QMAevB2dJCH-asZW9x5HX0_7xpoHHQV7_8fdb4Th917_PUJ8u_v6-Ig9OvYaXnwpK4rP9ubEnrR88tgU2c46Rn08voje9qe9HT177jWeVCJtfwDnwZwS_pGFDhwwgf8YVYMFdWJSeNxpd1cWJqOhw1ZE4Ds7GoUD1gBDc14rNKLIFvN0hdB2tmR6x_woOyamCTEMIJxnR-SV8DGj-yfRwrITB9230yaMYDf2Mm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