Skip to content

[clang] Preferred name not generated nor used to declare variables in DWARF when used as template argument in code #164730

@royitaqi

Description

@royitaqi

Problem

TL;DR Compiling the following code generates an object file whose DWARF doesn't contain the preferred name. This is true when compiling with -ggdb and with -glldb. Inspecting the DWARF shows that the variable is declared as Foo<Foo<int> >. The preferred name, i.e. BarInt (case sensitive), is no where to be found in the DWARF.

Code:

template <typename T> struct Foo;

typedef Foo<int> BarInt;

template <typename T>
struct [[clang::preferred_name(BarInt)]] Foo{};

int main() {
  // BarInt barInt;
  Foo<BarInt> fooBarInt;
  return 0;
}

DWARF:

0x00000033:     DW_TAG_variable
                  DW_AT_location	(DW_OP_fbreg +11)
                  DW_AT_name	("fooBarInt")
                  DW_AT_decl_file	("/Users/royshi/demo/preferred_name/two.cpp")
                  DW_AT_decl_line	(10)
                  DW_AT_type	(0x00000043 "Foo<Foo<int> >")

So lldb cannot print the preferred name:

(lldb) p fooBarInt
(Foo<Foo<int> >)  {}

Repro

Use the above source code (call it two.cpp), then:

~/public_llvm/build/bin/clang -O0 -glldb -c two.cpp   # or -ggdb

dwarfdump two.o

# Note: For me, the above clang cannot link, so I used xcrun clang++. It shouldn't matter which one you use.
xcrun clang++ two.o

lldb a.out -o "b two.cpp:10" -o "r" -o "p fooBarInt"

See compilation, dwarfdump, and lldb output:

I tested these on macOS. Haven't tested on Linux.

Note: If we uncomment that line // BarInt barInt;, the preferred name will be generated for barInt (type = BarInt), but not for fooBarInt (type = Foo<Foo<int > >; I'm expecting Foo<BarInt>, since the type BarInt now exists).

--

cc @Michael137 , @clayborg

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