[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
Thu Feb 25 10:36:38 PST 2021


akhuang updated this revision to Diff 326438.
akhuang marked an inline comment as done.
akhuang added a comment.

-Add LangOpts[CPlusPlus] to the attribute
-Maybe change the attribute to also override required complete types and change name to standalone_debug


Repository:
  rG LLVM Github Monorepo

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

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,28 @@
+// 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__((standalone_debug))
+#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) {}
+// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
+// DEBUG-SAME:              flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
+// WITHATTR-NOT: DIFlagFwdDecl
+
+template <typename T> struct Foo { Foo() {} T x; };
+extern template struct DEBUGASNEEDED Foo<int>;
+void func2(Foo<int> f) {}
+// DEBUG: !DICompositeType({{.*}}name: "Foo<int>"
+// DEBUG-SAME:             flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "Foo<int>"
+// WITHATTR-NOT: DIFlagFwdDecl
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2385,7 +2385,8 @@
   if (DebugKind == codegenoptions::DebugLineTablesOnly)
     return true;
 
-  if (DebugKind > codegenoptions::LimitedDebugInfo)
+  if (DebugKind > codegenoptions::LimitedDebugInfo ||
+      RD->hasAttr<StandaloneDebugAttr>())
     return false;
 
   if (!LangOpts.CPlusPlus)
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1660,6 +1660,14 @@
   let Documentation = [NoDebugDocs];
 }
 
+def StandaloneDebug : InheritableAttr {
+  let Spellings = [Clang<"standalone_debug">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+  let LangOpts = [CPlusPlus];
+}
+
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97411.326438.patch
Type: text/x-patch
Size: 2395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210225/5a6c9652/attachment.bin>


More information about the cfe-commits mailing list