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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Local class is not nested to a member function in DWARF after optimization
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    test_dwarf.h
```cpp
#include <stdio.h>

namespace myns
{
struct myclass
{
    int b;
    myclass() : b(100)
    {
        class ctornested
        {
          public:
 void foobar()
            {
                printf("assert %s\n", a);
            }
            char *a;
        } wat;
 wat.foobar();
        putc(b, stderr);
    }
};
} // namespace myns

__attribute__((__visibility__("default"))) extern void fglobal();
```

test_dwarf.cpp
```cpp
#include "test_dwarf.h"

void fglobal()
{
    myns::myclass{};
}
```

clang --version
```
clang version 19.1.7 (RESF 19.1.7-2.module+el8.10.0+1965+112b558b)
Target: aarch64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang/aarch64-redhat-linux-gnu-clang.cfg
```

Compile the program with `clang++ -g -O3 -std=c++17 -shared -fPIC -fvisibility=hidden -o libtest_dwarf.so *.cpp`

llvm-dwarfdump libtest_dwarf.so [rel.txt](https://github.com/user-attachments/files/21538092/rel.txt)

Class `ctornested` is now nested in a "subprogram" with no other info, where the `myns` namespace owns nothing about it, nor `myclass`. The local class doesn't have to be in a constructor; it happens to non-special member functions as well.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VUuPozgQ_jXOpQQypnkdcshjIo200q5mR9pjZKAAr4yN7KLTPb9-ZaC3k-6ZiVAsV331_mxL71VvEPcsO7LsvJMzDdbtfwxqkPZ1V9v2dU_o6drepOvigfEDy_n6NdMUtiJVptFzi8DSk6dW2Xhg6Zeg4gcjR_STbBDGV-ODrDgyfvDk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