diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1289,9 +1289,17 @@ addSourceLine(*IMDie, Module->getLine(), Module->getFile()); addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie); StringRef Name = Module->getName(); - if (!Name.empty()) + if (!Name.empty()) { addString(*IMDie, dwarf::DW_AT_name, Name); + // FIXME: if consumers ever start caring about handling + // unnamed import declarations such as `using ::nullptr_t` + // or `using namespace std::ranges`, we could add the + // import declaration into the accelerator table with the + // name being the one of the entity being imported. + DD->addAccelNamespace(*CUNode, Name, *IMDie); + } + // This is for imported module with renamed entities (such as variables and // subprograms). DINodeArray Elements = Module->getElements(); diff --git a/llvm/test/DebugInfo/Inputs/accel-imported-declaration.cpp b/llvm/test/DebugInfo/Inputs/accel-imported-declaration.cpp new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Inputs/accel-imported-declaration.cpp @@ -0,0 +1,15 @@ +// Compiled on MacOS using: +// clang++ -c -std=c++2a -gdwarf-4 -O0 -o accel-imported-declaration.macho-arm64.o + +namespace A { +namespace B { +namespace C { +int a = -1; +} // namespace C +} // namespace B + +namespace C = B::C; + +using namespace B::C; +using B::C::a; +} // namespace A diff --git a/llvm/test/DebugInfo/Inputs/accel-imported-declaration.macho-arm64.o b/llvm/test/DebugInfo/Inputs/accel-imported-declaration.macho-arm64.o new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@