-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][DebugInfo] Emit DW_AT_object_pointer on function definitions with explicit this
#122897
[clang][DebugInfo] Emit DW_AT_object_pointer on function definitions with explicit this
#122897
Conversation
…with explicit `this` We currently don't emit `DW_AT_object_pointer` on function declarations or definitions. The DWARFv5 spec doesn't mandate this attribute be present *only* for implicit object parameters: ``` If the member function entry describes a non-static member function, then that entry has a DW_AT_object_pointer attribute whose value is a reference to the formal parameter entry that corresponds to the object for which the function is called. That parameter also has a DW_AT_artificial attribute whose value is true. ``` The part about `DW_AT_artificial` seems overly restrictive, and not true for explicit object parameters. We probably should relax this part of the DWARF spec. This will help LLDB identify static vs. non-static member functions (see llvm#120856). GCC suffers from the same issue: https://godbolt.org/z/h4jeT54G5 Partially fixes llvm#120974
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-clang Author: Michael Buch (Michael137) ChangesWe currently don't emit If I interpreted the DWARFv5 spec correctly, it doesn't mandate this attribute be present only for implicit object parameters:
This patch attaches the The part about This will help LLDB identify static vs. non-static member functions (see #120856). Partially fixes #120974 Full diff: https://github.com/llvm/llvm-project/pull/122897.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index d7e5e95b7873a0..f9cba414dcfe2c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4829,6 +4829,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
if (IPD->getParameterKind() == ImplicitParamKind::CXXThis ||
IPD->getParameterKind() == ImplicitParamKind::ObjCSelf)
Flags |= llvm::DINode::FlagObjectPointer;
+ } else if (const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
+ if (PVD->isExplicitObjectParameter())
+ Flags |= llvm::DINode::FlagObjectPointer;
}
// Note: Older versions of clang used to emit byval references with an extra
diff --git a/clang/test/CodeGenCXX/debug-info-object-pointer.cpp b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
new file mode 100644
index 00000000000000..594d4da791ee84
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-object-pointer.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -x c++ -std=c++23 -debug-info-kind=limited -emit-llvm < %s | FileCheck %s
+
+// CHECK: !DISubprogram(name: "bar",
+// CHECK-SAME: flags: DIFlagPrototyped
+// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type
+// CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer
+//
+// // FIXME: DIFlagObjectPointer not attached to the explicit object
+// // argument in the subprogram declaration.
+// CHECK: !DISubprogram(name: "explicit_this",
+// flags: DIFlagPrototyped
+// CHECK-NOT: DIFlagObjectPointer
+// CHECK-NOT: DIFlagArtificial
+//
+// CHECK: !DILocalVariable(name: "this", arg: 1
+// CHECK-SAME: flags: DIFlagArtificial | DIFlagObjectPointer
+//
+// CHECK-NOT: DIFlagArtificial
+// CHECK: !DILocalVariable(arg: 1, {{.*}}, flags: DIFlagObjectPointer)
+
+struct Foo {
+ void bar() {}
+ void explicit_this(this Foo &&) {}
+};
+
+void f() {
+ Foo{}.bar();
+ Foo{}.explicit_this();
+}
|
@dwblaikie @adrian-prantl any thoughts on adjusting the DWARF spec to allow explicit |
I would suggest posting an issue to dwarf-discuss that just turns that into
and give an example. Also maybe of a language like Python where self is quite explicit. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/13812 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/38/builds/1830 Here is the relevant piece of the build log for the reference
|
…eclarations with explicit `this` (#122928) In llvm/llvm-project#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/llvm-project#120974
We currently don't emit
DW_AT_object_pointer
on function declarations or definitions. GCC suffers from the same issue: https://godbolt.org/z/h4jeT54G5Fixing this will help LLDB in identifying static vs. non-static member functions (see #120856).
If I interpreted the DWARFv5 spec correctly, it doesn't mandate this attribute be present only for implicit object parameters:
This patch attaches the
DW_AT_object_pointer
for function defintions. The declarations will be handled in a separate patch.The part about
DW_AT_artificial
seems overly restrictive, and not true for explicit object parameters. We probably should relax this part of the DWARF spec.Partially fixes #120974