[PATCH] D97411: [DebugInfo] Add an attribute to force type info to be emitted for types that are required to be complete.

Amy Huang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 24 13:13:47 PST 2021


akhuang created this revision.
akhuang added reviewers: rnk, dblaikie, rsmith.
Herald added a reviewer: aaron.ballman.
akhuang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was motivated by the fact that constructor type homing (debug info
optimization that we want to turn on by default) drops some libc++ types,
so an attribute would allow us to override constructor homing and emit
them anyway. I'm currently looking into the particular libc++ issue, but
even if we do fix that, this issue might come up elsewhere and it might be
nice to have this.

As I've implemented it now, the attribute isn't specific to the
constructor homing optimization and overrides all of the debug info
optimizations.

Open to discussion about naming, specifics on what the attribute should do, etc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97411

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/force-debug-attribute.cpp


Index: clang/test/CodeGenCXX/force-debug-attribute.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/force-debug-attribute.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
+// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
+
+#if SETATTR
+#define DEBUGASNEEDED __attribute__((force_debug_if_required_type))
+#else
+#define DEBUGASNEEDED
+#endif
+
+// Struct that isn't constructed, so its full type info should be omitted with
+// -debug-info-kind=constructor.
+struct DEBUGASNEEDED some_struct {
+  some_struct() {}
+};
+
+void func1(some_struct s) {}
+// void func2() { func1(); }
+// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
+// DEBUG-SAME:              flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
+// WITHATTR-NOT: DIFlagFwdDecl
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2399,6 +2399,10 @@
   if (!CXXDecl)
     return false;
 
+  // Don't omit definition if marked with attribute.
+  if (RD->hasAttr<ForceDebugIfRequiredTypeAttr>())
+    return false;
+
   // Only emit complete debug info for a dynamic class when its vtable is
   // emitted.  However, Microsoft debuggers don't resolve type information
   // across DLL boundaries, so skip this optimization if the class or any of its
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1660,6 +1660,13 @@
   let Documentation = [NoDebugDocs];
 }
 
+def ForceDebugIfRequiredType : InheritableAttr {
+  let Spellings = [Clang<"force_debug_if_required_type">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97411.326188.patch
Type: text/x-patch
Size: 2229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210224/07fa7463/attachment-0001.bin>


More information about the cfe-commits mailing list