aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2025-01-18 10:20:15 +0000
committerMichael Buch <michaelbuch12@gmail.com>2025-01-18 18:03:41 +0000
commita5fb2bbb2ad8488482843e2298fbe6f6a1d45bbd (patch)
tree0061cc383adfcf45876d00d050e62bb5ffccfd45 /clang/lib/CodeGen/CGDebugInfo.cpp
parent3f1be86a1acd5286bac16cae833481ee3f80dcbb (diff)
downloadllvm-a5fb2bbb2ad8488482843e2298fbe6f6a1d45bbd.zip
llvm-a5fb2bbb2ad8488482843e2298fbe6f6a1d45bbd.tar.gz
llvm-a5fb2bbb2ad8488482843e2298fbe6f6a1d45bbd.tar.bz2
Reapply "[clang][DebugInfo] Emit DW_AT_object_pointer on function declarations with explicit `this`" (#123455)
This reverts commit c3a935e3f967f8f22f5db240d145459ee621c1e0. 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, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index f88f56c..6cbcaf0 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2016,13 +2016,15 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
// First element is always return type. For 'void' functions it is NULL.
Elts.push_back(Args[0]);
- // "this" pointer is always first argument.
- // ThisPtr may be null if the member function has an explicit 'this'
- // parameter.
- if (!ThisPtr.isNull()) {
+ const bool HasExplicitObjectParameter = ThisPtr.isNull();
+
+ // "this" pointer is always first argument. For explicit "this"
+ // parameters, it will already be in Args[1].
+ if (!HasExplicitObjectParameter) {
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
- ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
+ ThisPtrType =
+ DBuilder.createObjectPointerType(ThisPtrType, /*Implicit=*/true);
Elts.push_back(ThisPtrType);
}
@@ -2030,6 +2032,13 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
for (unsigned i = 1, e = Args.size(); i != e; ++i)
Elts.push_back(Args[i]);
+ // Attach FlagObjectPointer to the explicit "this" parameter.
+ if (HasExplicitObjectParameter) {
+ assert(Elts.size() >= 2 && Args.size() >= 2 &&
+ "Expected at least return type and object parameter.");
+ Elts[1] = DBuilder.createObjectPointerType(Args[1], /*Implicit=*/false);
+ }
+
llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
@@ -5118,7 +5127,7 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
llvm::DIType *CachedTy = getTypeOrNull(QualTy);
if (CachedTy)
Ty = CachedTy;
- return DBuilder.createObjectPointerType(Ty);
+ return DBuilder.createObjectPointerType(Ty, /*Implicit=*/true);
}
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(