Skip to content

[Clang] Local class is not nested to a member function in DWARF after optimization #151602

@zhihaoy

Description

@zhihaoy

test_dwarf.h

#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

#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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.debuginfo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions