[PATCH] D88270: Add a verifier check that rejects unique DISubprogram function attachments.

Adrian Prantl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 17:06:46 PDT 2020


aprantl created this revision.
aprantl added reviewers: vsk, shafik.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
aprantl requested review of this revision.

Add a verifier check that rejects unique DISubprogram function attachments. They would crash the backend, which expects all DISubprograms that are not part of the type system to have a unit field.

      

Clang right before https://reviews.llvm.org/D79967 would generate this kind of broken IR.

      

rdar://problem/69534688


https://reviews.llvm.org/D88270

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll
  llvm/test/Verifier/unique-disubprogram.ll


Index: llvm/test/Verifier/unique-disubprogram.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/unique-disubprogram.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
+define i32 @_Z3foov() local_unnamed_addr !dbg !9 {
+  ret i32 5
+}
+!llvm.module.flags = !{!2}
+!llvm.dbg.cu = !{!5}
+!llvm.linker.options = !{}
+
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !6, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!6 = !DIFile(filename: "t.cpp", directory: "/")
+!7 = !{}
+; CHECK: function definition may only have a distinct !dbg attachment
+; CHECK: warning: ignoring invalid debug info
+!9 = !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !6, file: !6, line: 2, type: !11, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !7)
+!11 = !DISubroutineType(types: !7)
Index: llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll
===================================================================
--- llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll
+++ llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll
@@ -3,7 +3,7 @@
 !llvm.module.flags = !{!6}
 !llvm.dbg.cu = !{!5}
 
-!0 = !DISubprogram(name: "bar", linkageName: "_ZN3foo3barEv", line: 3, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagProtected | DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !4, scope: !1, type: !2)
+!0 = distinct !DISubprogram(name: "bar", linkageName: "_ZN3foo3barEv", line: 3, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagProtected | DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !4, scope: !1, type: !2)
 !1 = !DIFile(filename: "/foo", directory: "bar.cpp")
 !2 = !DISubroutineType(types: !3)
 !3 = !{null}
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -2433,6 +2433,10 @@
                  "function must have a single !dbg attachment", &F, I.second);
         AssertDI(isa<DISubprogram>(I.second),
                  "function !dbg attachment must be a subprogram", &F, I.second);
+        AssertDI(cast<DISubprogram>(I.second)->isDistinct(),
+                 "function definition may only have a distinct !dbg attachment",
+                 &F);
+
         auto *SP = cast<DISubprogram>(I.second);
         const Function *&AttachedTo = DISubprogramAttachments[SP];
         AssertDI(!AttachedTo || AttachedTo == &F,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88270.294203.patch
Type: text/x-patch
Size: 2623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200925/7457aebb/attachment.bin>


More information about the llvm-commits mailing list