[PATCH] D96044: DebugInfo: Emit "LocalToUnit" flag on local member function decls.

James Y Knight via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 08:16:51 PST 2021


jyknight created this revision.
jyknight added a reviewer: dblaikie.
Herald added a subscriber: inglorion.
jyknight requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously, the definition was so-marked, but the declaration was
not. This resulted in LLVM's dwarf emission treating the function as
being external, and incorrectly emitting DW_AT_external.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96044

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


Index: clang/test/CodeGenCXX/debug-info-class.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-class.cpp
+++ clang/test/CodeGenCXX/debug-info-class.cpp
@@ -24,12 +24,14 @@
 C::~C() {
 }
 
+namespace {
 struct D {
-  D();
-  virtual ~D();
+  D() {}
+  virtual ~D() {}
   void func() {
   }
 };
+} // namespace
 
 struct E {
   E();
@@ -135,11 +137,13 @@
 // CHECK-SAME:                     DIFlagStaticMember
 // CHECK: [[C_DTOR]] = !DISubprogram(name: "~C"
 
-// CHECK: [[D:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "D"
+// CHECK: [[D:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D"
 // CHECK-SAME:             size:
-// CHECK-SAME:             DIFlagFwdDecl
 // CHECK-NOT:              identifier:
 // CHECK-SAME:             ){{$}}
+// CHECK: [[D_FUNC_DECL:![0-9]*]] = !DISubprogram(name: "func",{{.*}} scope: [[D]]
+// CHECK-SAME:             DISPFlagLocalToUnit
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "E"
 // CHECK-SAME:             DIFlagFwdDecl
 // CHECK-NOT:              identifier:
@@ -150,11 +154,10 @@
 // CHECK-SAME:             ){{$}}
 
 // CHECK: !DISubprogram(name: "func",{{.*}} scope: [[D]]
-// CHECK-SAME:          DISPFlagDefinition
-// CHECK-SAME:          declaration: [[D_FUNC_DECL:![0-9]*]]
-// CHECK: [[D_FUNC_DECL]] = !DISubprogram(name: "func",{{.*}} scope: [[D]]
+// CHECK-SAME:          DISPFlagLocalToUnit | DISPFlagDefinition
+// CHECK-SAME:          declaration: [[D_FUNC_DECL]]
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "inner",{{.*}} line: 50
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "inner",{{.*}} line: 52
 // CHECK-NOT: DIFlagFwdDecl
 // CHECK-SAME: elements: [[G_INNER_MEM:![0-9]*]]
 // CHECK-SAME: identifier: "_ZTSN1G5innerE"
@@ -170,5 +173,5 @@
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "HdrSize"
 //
-// CHECK: ![[EXCEPTLOC]] = !DILocation(line: 91,
-// CHECK: ![[RETLOC]] = !DILocation(line: 90,
+// CHECK: ![[EXCEPTLOC]] = !DILocation(line: 93,
+// CHECK: ![[RETLOC]] = !DILocation(line: 92,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1729,6 +1729,8 @@
     Flags |= llvm::DINode::FlagLValueReference;
   if (Method->getRefQualifier() == RQ_RValue)
     Flags |= llvm::DINode::FlagRValueReference;
+  if (!Method->isExternallyVisible())
+    SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
   if (CGM.getLangOpts().Optimize)
     SPFlags |= llvm::DISubprogram::SPFlagOptimized;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96044.321440.patch
Type: text/x-patch
Size: 2724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210204/0c4bdf7a/attachment.bin>


More information about the cfe-commits mailing list