Skip to content

Commit a5fb2bb

Browse files
committed
Reapply "[clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit this" (#123455)
This reverts commit c3a935e. The only change to the reverted commit is that this also updates the OCaml bindings according to the C debug-info API changes. The build failure originally introduced was: ``` FAILED: bindings/ocaml/debuginfo/debuginfo_ocaml.o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo/debuginfo_ocaml.o cd /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo && /usr/bin/ocamlfind ocamlc -c /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo/debuginfo_ocaml.c -ccopt "-I/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/bindings/ocaml/debuginfo/../llvm -D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -DEXPENSIVE_CHECKS -D_GLIBCXX_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/1/llvm-clang-x86_64-expensive-checks-debian/build/include -I/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/include -DNDEBUG " /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo/debuginfo_ocaml.c: In function ‘llvm_dibuild_create_object_pointer_type’: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo/debuginfo_ocaml.c:620:30: error: too few arguments to function ‘LLVMDIBuilderCreateObjectPointerType’ 620 | LLVMMetadataRef Metadata = LLVMDIBuilderCreateObjectPointerType( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bindings/ocaml/debuginfo/debuginfo_ocaml.c:23: /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/include/llvm-c/DebugInfo.h:880:17: note: declared here 880 | LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
1 parent 3f1be86 commit a5fb2bb

File tree

9 files changed

+47
-29
lines changed

9 files changed

+47
-29
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

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

2019-
// "this" pointer is always first argument.
2020-
// ThisPtr may be null if the member function has an explicit 'this'
2021-
// parameter.
2022-
if (!ThisPtr.isNull()) {
2019+
const bool HasExplicitObjectParameter = ThisPtr.isNull();
2020+
2021+
// "this" pointer is always first argument. For explicit "this"
2022+
// parameters, it will already be in Args[1].
2023+
if (!HasExplicitObjectParameter) {
20232024
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
20242025
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
2025-
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2026+
ThisPtrType =
2027+
DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
20262028
Elts.push_back(ThisPtrType);
20272029
}
20282030

20292031
// Copy rest of the arguments.
20302032
for (unsigned i = 1, e = Args.size(); i != e; ++i)
20312033
Elts.push_back(Args[i]);
20322034

2035+
// Attach FlagObjectPointer to the explicit "this" parameter.
2036+
if (HasExplicitObjectParameter) {
2037+
assert(Elts.size() >= 2 && Args.size() >= 2 &&
2038+
"Expected at least return type and object parameter.");
2039+
Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
2040+
}
2041+
20332042
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
20342043

20352044
return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5118,7 +5127,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
51185127
llvm::DIType *CachedTy = getTypeOrNull(QualTy);
51195128
if (CachedTy)
51205129
Ty = CachedTy;
5121-
return DBuilder.createObjectPointerType(Ty);
5130+
return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
51225131
}
51235132

51245133
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/bindings/ocaml/debuginfo/debuginfo_ocaml.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,10 @@ value llvm_dibuild_create_member_pointer_type_bytecode(value *argv, int argn) {
616616
);
617617
}
618618

619-
value llvm_dibuild_create_object_pointer_type(value Builder, value Type) {
619+
value llvm_dibuild_create_object_pointer_type(value Builder, value Type,
620+
value Implicit) {
620621
LLVMMetadataRef Metadata = LLVMDIBuilderCreateObjectPointerType(
621-
DIBuilder_val(Builder), Metadata_val(Type));
622+
DIBuilder_val(Builder), Metadata_val(Type), Bool_val(Implicit));
622623
return to_val(Metadata);
623624
}
624625

llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ external dibuild_create_member_pointer_type :
398398
= "llvm_dibuild_create_member_pointer_type_bytecode" "llvm_dibuild_create_member_pointer_type_native"
399399

400400
external dibuild_create_object_pointer_type :
401-
lldibuilder -> Llvm.llmetadata -> Llvm.llmetadata
401+
lldibuilder -> Llvm.llmetadata -> implicit:bool -> Llvm.llmetadata
402402
= "llvm_dibuild_create_object_pointer_type"
403403

404404
external dibuild_create_qualified_type :

llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,11 @@ val dibuild_create_member_pointer_type :
471471
a pointer to member. See LLVMDIBuilderCreateMemberPointerType *)
472472

473473
val dibuild_create_object_pointer_type :
474-
lldibuilder -> Llvm.llmetadata -> Llvm.llmetadata
474+
lldibuilder -> Llvm.llmetadata -> implicit:bool -> Llvm.llmetadata
475475
(** [dibuild_create_object_pointer_type dib ty] Create a uniqued DIType* clone
476-
with FlagObjectPointer and FlagArtificial set. [dib] is the dibuilder
477-
value and [ty] the underlying type to which this pointer points. *)
476+
with FlagObjectPointer. [dib] is the dibuilder
477+
value and [ty] the underlying type to which this pointer points. If
478+
[implicit] is true, also set FlagArtificial. *)
478479

479480
val dibuild_create_qualified_type :
480481
lldibuilder -> tag:int -> Llvm.llmetadata -> Llvm.llmetadata

llvm/include/llvm-c/DebugInfo.h

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

872872
/**
873-
* Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
873+
* Create a uniqued DIType* clone with FlagObjectPointer. If \c Implicit
874+
* is true, then also set FlagArtificial.
874875
* \param Builder The DIBuilder.
875876
* \param Type The underlying type to which this pointer points.
877+
* \param Implicit Indicates whether this pointer was implicitly generated
878+
* (i.e., not spelled out in source).
876879
*/
877-
LLVMMetadataRef
878-
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
879-
LLVMMetadataRef Type);
880+
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
881+
LLVMMetadataRef Type,
882+
LLVMBool Implicit);
880883

881884
/**
882885
* 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
@@ -662,9 +662,9 @@ namespace llvm {
662662
/// Create a uniqued clone of \p Ty with FlagArtificial set.
663663
static DIType *createArtificialType(DIType *Ty);
664664

665-
/// Create a uniqued clone of \p Ty with FlagObjectPointer and
666-
/// FlagArtificial set.
667-
static DIType *createObjectPointerType(DIType *Ty);
665+
/// Create a uniqued clone of \p Ty with FlagObjectPointer set.
666+
/// If \p Implicit is true, also set FlagArtificial.
667+
static DIType *createObjectPointerType(DIType *Ty, bool Implicit);
668668

669669
/// Create a permanent forward-declared type.
670670
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
@@ -644,11 +644,15 @@ DIType *DIBuilder::createArtificialType(DIType *Ty) {
644644
return createTypeWithFlags(Ty, DINode::FlagArtificial);
645645
}
646646

647-
DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
647+
DIType *DIBuilder::createObjectPointerType(DIType *Ty, bool Implicit) {
648648
// FIXME: Restrict this to the nodes where it's valid.
649649
if (Ty->isObjectPointer())
650650
return Ty;
651-
DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
651+
DINode::DIFlags Flags = DINode::FlagObjectPointer;
652+
653+
if (Implicit)
654+
Flags |= DINode::FlagArtificial;
655+
652656
return createTypeWithFlags(Ty, Flags);
653657
}
654658

llvm/lib/IR/DebugInfo.cpp

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

1435-
LLVMMetadataRef
1436-
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
1437-
LLVMMetadataRef Type) {
1438-
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
1435+
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
1436+
LLVMMetadataRef Type,
1437+
LLVMBool Implicit) {
1438+
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type),
1439+
Implicit));
14391440
}
14401441

14411442
LLVMMetadataRef

0 commit comments

Comments
 (0)