[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

Bruno De Fraine via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 23 04:30:33 PDT 2021


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

Fix suggested by Yuanfang Chen:

Non-distinct debuginfo is attached to the function due to the undecorated declaration. Later, when seeing the function definition and `nodebug` attribute, the non-distinct debuginfo should be cleared.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104777

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-nodebug2.cpp


Index: clang/test/CodeGen/attr-nodebug2.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug))
+void t1()
+{
+  int a = 10;
+  a++;
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z3usev()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:       !dbg
+// CHECK:       }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @_Z2t1v()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:       }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1300,8 +1300,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr<NoDebugAttr>())
-    DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr<NoDebugAttr>()) {
+    // Clear non-distinct debug info that was possibly attached to
+    // the function due to a declaration with the nodebug attribute
+    if (Fn)
+      Fn->setSubprogram(nullptr);
+    // Disable debug info indefinitely for this function
+    DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104777.353914.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210623/ce28c3b8/attachment.bin>


More information about the cfe-commits mailing list