Skip to content

Commit e17f52d

Browse files
committed
Add a verifier check that rejects non-distinct 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
1 parent 9a47674 commit e17f52d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,10 @@ void Verifier::visitFunction(const Function &F) {
24332433
"function must have a single !dbg attachment", &F, I.second);
24342434
AssertDI(isa<DISubprogram>(I.second),
24352435
"function !dbg attachment must be a subprogram", &F, I.second);
2436+
AssertDI(cast<DISubprogram>(I.second)->isDistinct(),
2437+
"function definition may only have a distinct !dbg attachment",
2438+
&F);
2439+
24362440
auto *SP = cast<DISubprogram>(I.second);
24372441
const Function *&AttachedTo = DISubprogramAttachments[SP];
24382442
AssertDI(!AttachedTo || AttachedTo == &F,

llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
!llvm.module.flags = !{!6}
44
!llvm.dbg.cu = !{!5}
55

6-
!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)
6+
!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)
77
!1 = !DIFile(filename: "/foo", directory: "bar.cpp")
88
!2 = !DISubroutineType(types: !3)
99
!3 = !{null}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
2+
define i32 @_Z3foov() local_unnamed_addr !dbg !9 {
3+
ret i32 5
4+
}
5+
!llvm.module.flags = !{!2}
6+
!llvm.dbg.cu = !{!5}
7+
!llvm.linker.options = !{}
8+
9+
!2 = !{i32 2, !"Debug Info Version", i32 3}
10+
!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !6, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
11+
!6 = !DIFile(filename: "t.cpp", directory: "/")
12+
!7 = !{}
13+
; CHECK: function definition may only have a distinct !dbg attachment
14+
; CHECK: warning: ignoring invalid debug info
15+
!9 = !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !6, file: !6, line: 2, type: !11, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !7)
16+
!11 = !DISubroutineType(types: !7)

0 commit comments

Comments
 (0)