[PATCH] D153362: [clang][DebugInfo] Emit DW_AT_defaulted for defaulted C++ member functions

Michael Buch via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 08:50:37 PDT 2023


Michael137 updated this revision to Diff 532957.
Michael137 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153362/new/

https://reviews.llvm.org/D153362

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-defaulted.cpp


Index: clang/test/CodeGenCXX/debug-info-defaulted.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-defaulted.cpp
@@ -0,0 +1,38 @@
+// Test for debug info for C++ defaulted member functions
+
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - \
+// RUN:   -O0 -debug-info-kind=standalone -std=c++20 | FileCheck %s
+
+// CHECK:     DISubprogram(name: "defaulted", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+// CHECK:     DISubprogram(name: "~defaulted", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedOutOfClass)
+// CHECK:     DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, spFlags: 0)
+// CHECK:     DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, spFlags: 0)
+// CHECK:     DISubprogram(name: "operator==", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+// CHECK-NOT: DISubprogram(name: "implicit_defaulted"
+struct defaulted {
+  // inline defaulted
+  defaulted() = default;
+
+  // out-of-line defaulted (inline keyword
+  // shouldn't change that)
+  inline ~defaulted();
+
+  // These shouldn't produce a defaulted-ness DI flag
+  // (though technically they are DW_DEFAULTED_no)
+  defaulted& operator=(defaulted const&) { return *this; }
+  defaulted& operator=(defaulted &&);
+
+  bool operator==(defaulted const&) const = default;
+};
+
+defaulted::~defaulted() = default;
+defaulted& defaulted::operator=(defaulted &&) { return *this; }
+
+// All ctors/dtors are implicitly defatuled.
+// So no DW_AT_defaulted expected for these.
+struct implicit_defaulted {};
+
+void foo() {
+  defaulted d;
+  implicit_defaulted i;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1948,6 +1948,14 @@
   if (Method->getCanonicalDecl()->isDeleted())
     SPFlags |= llvm::DISubprogram::SPFlagDeleted;
 
+  // The defaulted-ness of an out-of-class method is a property of its
+  // definition. Hence, query the definition instead.
+  if (auto const *Def = Method->getDefinition())
+    if (Def->isExplicitlyDefaulted())
+      SPFlags |= (Def->isOutOfLine())
+                     ? llvm::DISubprogram::SPFlagDefaultedOutOfClass
+                     : llvm::DISubprogram::SPFlagDefaultedInClass;
+
   if (Method->isNoReturn())
     Flags |= llvm::DINode::FlagNoReturn;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153362.532957.patch
Type: text/x-patch
Size: 2492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230620/1c07c4f2/attachment.bin>


More information about the cfe-commits mailing list