[PATCH] D60713: [IR] Add DISuprogram and DIE for func decl of an external

Djordje Todorovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 4 03:35:54 PDT 2019


djtodoro updated this revision to Diff 202892.
djtodoro added a comment.

-Address suggestions
-Document this


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

https://reviews.llvm.org/D60713

Files:
  docs/LangRef.rst
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/IR/Verifier.cpp
  test/Verifier/metadata-function-dbg.ll


Index: test/Verifier/metadata-function-dbg.ll
===================================================================
--- test/Verifier/metadata-function-dbg.ll
+++ test/Verifier/metadata-function-dbg.ll
@@ -1,8 +1,11 @@
 ; RUN: llvm-as %s -disable-output 2>&1 | FileCheck %s
 
-; CHECK:      function declaration may not have a !dbg attachment
+; CHECK:      function declaration may only have a unique !dbg attachment
 declare !dbg !4 void @f1()
 
+; CHECK-NOT:      function declaration may only have a unique !dbg attachment
+declare !dbg !6 void @f5()
+
 ; CHECK:      function must have a single !dbg attachment
 define void @f2() !dbg !4 !dbg !4 {
   unreachable
@@ -31,7 +34,9 @@
 !0 = !{i32 2, !"Debug Info Version", i32 3}
 
 !llvm.dbg.cu = !{!1}
-!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2)
+!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, retainedTypes: !5)
 !2 = !DIFile(filename: "t.c", directory: "/path/to/dir")
 !3 = !{}
 !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, unit: !1)
+!5 = !{!6}
+!6 = !DISubprogram(name: "f5", scope: !1, file: !2, unit: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
Index: lib/IR/Verifier.cpp
===================================================================
--- lib/IR/Verifier.cpp
+++ lib/IR/Verifier.cpp
@@ -2223,8 +2223,11 @@
            MDs.empty() ? nullptr : MDs.front().second);
   } else if (F.isDeclaration()) {
     for (const auto &I : MDs) {
-      AssertDI(I.first != LLVMContext::MD_dbg,
-               "function declaration may not have a !dbg attachment", &F);
+      // This is used for call site debug information.
+      AssertDI(I.first != LLVMContext::MD_dbg ||
+                   !cast<DISubprogram>(I.second)->isDistinct(),
+               "function declaration may only have a unique !dbg attachment",
+               &F);
       Assert(I.first != LLVMContext::MD_prof,
              "function declaration may not have a !prof attachment", &F);
 
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -669,6 +669,11 @@
     NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
   }
 
+  // Create DIEs for function declarations used for call site debug info.
+  for (auto Scope : DIUnit->getRetainedTypes())
+    if (auto *SP = dyn_cast_or_null<DISubprogram>(Scope))
+      NewCU.getOrCreateSubprogramDIE(SP);
+
   CUMap.insert({DIUnit, &NewCU});
   CUDieMap.insert({&NewCU.getUnitDie(), &NewCU});
   return NewCU;
Index: docs/LangRef.rst
===================================================================
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -4566,10 +4566,12 @@
 """"""""""""
 
 ``DISubprogram`` nodes represent functions from the source language. A
-``DISubprogram`` may be attached to a function definition using ``!dbg``
-metadata. The ``variables:`` field points at :ref:`variables <DILocalVariable>`
-that must be retained, even if their IR counterparts are optimized out of
-the IR. The ``type:`` field must point at an :ref:`DISubroutineType`.
+distinct ``DISubprogram`` may be attached to a function definition using
+``!dbg`` metadata. A unique ``DISubprogram`` may be attached to a function
+declaration used for call site debug info. The ``variables:`` field points at
+:ref:`variables <DILocalVariable>` that must be retained, even if their IR
+counterparts are optimized out of the IR. The ``type:`` field must point at an
+:ref:`DISubroutineType`.
 
 .. _DISubprogramDeclaration:
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60713.202892.patch
Type: text/x-patch
Size: 3597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190604/40df9f2f/attachment.bin>


More information about the llvm-commits mailing list