Skip to content

Commit 6576726

Browse files
committed
[llvm][DebugInfo] Add DW_TAG_imported_declaration to accelerator tables
**Summary** After this patch, `DW_TAG_imported_declaration`s will be emitted into the DWARF accelerator tables (under `.apple_namespaces`) **Motivation** Currently LLDB expression evaluation doesn't see through namespace aliases. This is because LLDB only considers namespaces that are part of `.apple_namespaces` when building a nested namespace identifier for C++, which currently doesn't include import declarations. The alternative to putting imports into accelerator tables is to do a linear scan of a `DW_TAG_namespace` and look for import declarations that look like they would satisfy the lookup request, which is prohibitively expensive. **Testing** * Added unit-test Differential Revision: https://reviews.llvm.org/D143397
1 parent 8b6ae9b commit 6576726

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,17 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE(
12891289
addSourceLine(*IMDie, Module->getLine(), Module->getFile());
12901290
addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
12911291
StringRef Name = Module->getName();
1292-
if (!Name.empty())
1292+
if (!Name.empty()) {
12931293
addString(*IMDie, dwarf::DW_AT_name, Name);
12941294

1295+
// FIXME: if consumers ever start caring about handling
1296+
// unnamed import declarations such as `using ::nullptr_t`
1297+
// or `using namespace std::ranges`, we could add the
1298+
// import declaration into the accelerator table with the
1299+
// name being the one of the entity being imported.
1300+
DD->addAccelNamespace(*CUNode, Name, *IMDie);
1301+
}
1302+
12951303
// This is for imported module with renamed entities (such as variables and
12961304
// subprograms).
12971305
DINodeArray Elements = Module->getElements();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Compiled on MacOS using:
2+
// clang++ -c -std=c++2a -gdwarf-4 -O0 -o accel-imported-declaration.macho-arm64.o
3+
4+
namespace A {
5+
namespace B {
6+
namespace C {
7+
int a = -1;
8+
} // namespace C
9+
} // namespace B
10+
11+
namespace C = B::C;
12+
13+
using namespace B::C;
14+
using B::C::a;
15+
} // namespace A
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
RUN: llvm-dwarfdump -v %p/Inputs/accel-imported-declaration.macho-arm64.o | FileCheck %s
2+
RUN: llvm-dwarfdump -verify %p/Inputs/accel-imported-declaration.macho-arm64.o | FileCheck %s --check-prefix=VERIFY
3+
4+
Gather some DIE indexes to verify the accelerator table contents.
5+
6+
CHECK: .debug_info contents
7+
CHECK: {{.*}}DW_TAG_namespace
8+
CHECK: DW_AT_name{{.*}}"A"
9+
CHECK: {{.*}}DW_TAG_namespace
10+
CHECK: DW_AT_name{{.*}}"B"
11+
CHECK: [[NAMESPACE:0x[0-9a-f]*]]:{{.*}}DW_TAG_namespace
12+
CHECK: DW_AT_name{{.*}}"C"
13+
CHECK: [[IMPORTED:0x[0-9a-f]*]]:{{.*}}DW_TAG_imported_declaration
14+
CHECK: DW_AT_name{{.*}}"C"
15+
16+
Check that the .apple_namespaces section contains two entries for "namespace C"
17+
18+
CHECK: .apple_namespaces contents:
19+
CHECK: Bucket 1 [
20+
CHECK-NEXT: Hash {{.*}} [
21+
CHECK-NEXT: Name{{.*}} {
22+
CHECK-NEXT: String: {{.*}} "C"
23+
CHECK-NEXT: Data 0 [
24+
CHECK-NEXT: Atom[0]: [[NAMESPACE]]
25+
CHECK-NEXT: ]
26+
CHECK-NEXT: Data 1 [
27+
CHECK-NEXT: Atom[0]: [[IMPORTED]]
28+
CHECK-NEXT: ]
29+
CHECK-NEXT: }
30+
CHECK-NEXT: ]
31+
CHECK-NEXT: ]
32+
33+
VERIFY: Verifying .apple_names...
34+
VERIFY-NEXT: Verifying .apple_types...
35+
VERIFY-NEXT: Verifying .apple_namespaces...
36+
VERIFY-NEXT: Verifying .apple_objc...
37+
VERIFY-NEXT: No errors.

0 commit comments

Comments
 (0)