[PATCH] D90719: [DebugInfo] Modify ctor homing as workaround for unconstructed libcxx types

Amy Huang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 14:40:37 PST 2020


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

There are some types in libcxx that are used but their constructors
are not called (__hash_node, __hash_value_type, __tree_node, __value_type),
which means that with constructor homing, the types are not complete.

This patch avoids using ctor homing if there are no constructors in
the class definition. So it'll mean we emit some extra debug info in places.

I also re-measured the size of object files in a clang build
-debug-info-kind=limited:     5568746k
-debug-info-kind=constructor: 2695028k

  after this patch: 2685607k

So they're ~10mb larger after this change, which is not too bad.

In terms of testing, in chromium (on windows) there's visualization for libcxx
types and all of those types are displayed correctly after this patch, so I
think that means all the STL types are getting emitted now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90719

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


Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -74,6 +74,14 @@
   auto func = [&]() {};
 }
 
+// Test that a class that otherwise should be subject to constructor homing
+// is not because its constructor isn't used in this translation unit.
+// CHECK-DAG: !DICompositeType({{.*}}name: "M",{{.*}}DIFlagTypePassByValue
+class M {
+  B b;
+};
+void f(M m) {}
+
 // Check that types are being added to retained types list.
 // CHECK-DAG: !DICompileUnit{{.*}}retainedTypes: ![[RETAINED:[0-9]+]]
 // CHECK-DAG: ![[RETAINED]] = {{.*}}![[C]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2300,7 +2300,16 @@
   if (isClassOrMethodDLLImport(RD))
     return false;
 
-  return !RD->isLambda() && !RD->isAggregate() &&
+  // Attempt to avoid using constructor homing if a class is used but for
+  // whatever reason is not constructed. Constructors are added to the class
+  // definition when used, so use the existence of constructors here as a
+  // heuristic.
+  bool HasCtor = false;
+  for (auto *Ctor : RD->ctors())
+    if (!Ctor->isCopyOrMoveConstructor() && !Ctor->isDeleted())
+      HasCtor = true;
+
+  return HasCtor && !RD->isLambda() && !RD->isAggregate() &&
          !RD->hasTrivialDefaultConstructor() &&
          !RD->hasConstexprNonCopyMoveConstructor();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90719.302692.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201103/d39f95bf/attachment.bin>


More information about the cfe-commits mailing list