Skip to content

Commit 7c72941

Browse files
authored
[llvm][DebugInfo] Attach object-pointer to DISubprogram declarations (#122742)
Currently Clang only attaches `DW_AT_object_pointer` to `DW_TAG_subprogram` definitions. LLDB constructs C++ method types from their `DW_TAG_subprogram` declaration, which is also the point at which it needs to determine whether a method is static or not. LLDB's heuristic for this could be very simple if we emitted `DW_AT_object_pointer` on declarations. But since we don't, LLDB has to guess whether an argument is an implicit object parameter based on the DW_AT_name and DW_AT_type. To simplify LLDB's job (and to eventually support C++23's explicit object parameters), this patch adds the `DIFlagObjectPointer` to `DISubprogram` declarations. For reference, GCC attaches the object-pointer DIE to both the definition and declaration: https://godbolt.org/z/3TWjTfWon Fixes #120973
1 parent ba44d7b commit 7c72941

File tree

6 files changed

+1647
-1563
lines changed

6 files changed

+1647
-1563
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,9 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
849849
}
850850
}
851851

852-
void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) {
852+
DIE *DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) {
853+
// Args[0] is the return type.
854+
DIE *ObjectPointer = nullptr;
853855
for (unsigned i = 1, N = Args.size(); i < N; ++i) {
854856
const DIType *Ty = Args[i];
855857
if (!Ty) {
@@ -860,8 +862,14 @@ void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) {
860862
addType(Arg, Ty);
861863
if (Ty->isArtificial())
862864
addFlag(Arg, dwarf::DW_AT_artificial);
865+
if (Ty->isObjectPointer()) {
866+
assert(!ObjectPointer && "Can't have more than one object pointer");
867+
ObjectPointer = &Arg;
868+
}
863869
}
864870
}
871+
872+
return ObjectPointer;
865873
}
866874

867875
void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {
@@ -1358,7 +1366,8 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
13581366

13591367
// Add arguments. Do not add arguments for subprogram definition. They will
13601368
// be handled while processing variables.
1361-
constructSubprogramArguments(SPDie, Args);
1369+
if (auto *ObjectPointer = constructSubprogramArguments(SPDie, Args))
1370+
addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, *ObjectPointer);
13621371
}
13631372

13641373
addThrownTypes(SPDie, SP->getThrownTypes());

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ class DwarfUnit : public DIEUnit {
268268
void constructContainingTypeDIEs();
269269

270270
/// Construct function argument DIEs.
271-
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args);
271+
///
272+
/// \returns DIE of the object pointer if one exists. Nullptr otherwise.
273+
DIE *constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args);
272274

273275
/// Create a DIE with the given Tag, add the DIE to its parent, and
274276
/// call insertDIE if MD is not null.

0 commit comments

Comments
 (0)