Skip to content

Commit 9f66ff9

Browse files
Michael137ronlieb
authored andcommitted
[clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit this (llvm#122928)
In llvm#122897 we started attaching `DW_AT_object_pointer` to function definitions. This patch does the same but for function declarations (which we do for implicit object pointers already). Fixes llvm#120974
1 parent 50907c0 commit 9f66ff9

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,20 +2067,29 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
20672067
// First element is always return type. For 'void' functions it is NULL.
20682068
Elts.push_back(Args[0]);
20692069

2070-
// "this" pointer is always first argument.
2071-
// ThisPtr may be null if the member function has an explicit 'this'
2072-
// parameter.
2073-
if (!ThisPtr.isNull()) {
2070+
const bool HasExplicitObjectParameter = ThisPtr.isNull();
2071+
2072+
// "this" pointer is always first argument. For explicit "this"
2073+
// parameters, it will already be in Args[1].
2074+
if (!HasExplicitObjectParameter) {
20742075
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
20752076
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2076-
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2077+
ThisPtrType =
2078+
DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
20772079
Elts.push_back(ThisPtrType);
20782080
}
20792081

20802082
// Copy rest of the arguments.
20812083
for (unsigned i = 1, e = Args.size(); i != e; ++i)
20822084
Elts.push_back(Args[i]);
20832085

2086+
// Attach FlagObjectPointer to the explicit "this" parameter.
2087+
if (HasExplicitObjectParameter) {
2088+
assert(Elts.size() >= 2 && Args.size() >= 2 &&
2089+
"Expected at least return type and object parameter.");
2090+
Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
2091+
}
2092+
20842093
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
20852094

20862095
return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5499,7 +5508,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
54995508
llvm::DIType *CachedTy = getTypeOrNull(QualTy);
55005509
if (CachedTy)
55015510
Ty = CachedTy;
5502-
return DBuilder.createObjectPointerType(Ty);
5511+
return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
55035512
}
55045513

55055514
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(

clang/test/CodeGenCXX/debug-info-object-pointer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
66
// CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer
77
//
8-
// // FIXME: DIFlagObjectPointer not attached to the explicit object
9-
// // argument in the subprogram declaration.
108
// CHECK: !DISubprogram(name: "explicit_this",
119
// flags: DIFlagPrototyped
12-
// CHECK-NOT: DIFlagObjectPointer
13-
// CHECK-NOT: DIFlagArtificial
10+
//
11+
// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type
12+
// CHECK-SAME: flags: DIFlagObjectPointer)
1413
//
1514
// CHECK: !DILocalVariable(name: "this", arg: 1
1615
// CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer

llvm/include/llvm-c/DebugInfo.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,16 @@ LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
876876
LLVMMetadataRef Ty);
877877

878878
/**
879-
* Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
879+
* Create a uniqued DIType* clone with FlagObjectPointer. If \c Implicit
880+
* is true, then also set FlagArtificial.
880881
* \param Builder The DIBuilder.
881882
* \param Type The underlying type to which this pointer points.
883+
* \param Implicit Indicates whether this pointer was implicitly generated
884+
* (i.e., not spelled out in source).
882885
*/
883-
LLVMMetadataRef
884-
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
885-
LLVMMetadataRef Type);
886+
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
887+
LLVMMetadataRef Type,
888+
LLVMBool Implicit);
886889

887890
/**
888891
* Create debugging information entry for a qualified

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ namespace llvm {
681681
/// Create a uniqued clone of \p Ty with FlagArtificial set.
682682
static DIType *createArtificialType(DIType *Ty);
683683

684-
/// Create a uniqued clone of \p Ty with FlagObjectPointer and
685-
/// FlagArtificial set.
686-
static DIType *createObjectPointerType(DIType *Ty);
684+
/// Create a uniqued clone of \p Ty with FlagObjectPointer set.
685+
/// If \p Implicit is true, also set FlagArtificial.
686+
static DIType *createObjectPointerType(DIType *Ty, bool Implicit);
687687

688688
/// Create a permanent forward-declared type.
689689
DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,

llvm/lib/IR/DIBuilder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,15 @@ DIType *DIBuilder::createArtificialType(DIType *Ty) {
650650
return createTypeWithFlags(Ty, DINode::FlagArtificial);
651651
}
652652

653-
DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
653+
DIType *DIBuilder::createObjectPointerType(DIType *Ty, bool Implicit) {
654654
// FIXME: Restrict this to the nodes where it's valid.
655655
if (Ty->isObjectPointer())
656656
return Ty;
657-
DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
657+
DINode::DIFlags Flags = DINode::FlagObjectPointer;
658+
659+
if (Implicit)
660+
Flags |= DINode::FlagArtificial;
661+
658662
return createTypeWithFlags(Ty, Flags);
659663
}
660664

llvm/lib/IR/DebugInfo.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,10 +1472,11 @@ LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
14721472
PropertyAttributes, unwrapDI<DIType>(Ty)));
14731473
}
14741474

1475-
LLVMMetadataRef
1476-
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
1477-
LLVMMetadataRef Type) {
1478-
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
1475+
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
1476+
LLVMMetadataRef Type,
1477+
LLVMBool Implicit) {
1478+
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type),
1479+
Implicit));
14791480
}
14801481

14811482
LLVMMetadataRef

0 commit comments

Comments
 (0)