From 271da2aac13de3f3e34f43ae7308f5505b8164b6 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 24 Sep 2020 16:59:36 -0700 Subject: [PATCH 1/5] 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 (cherry picked from commit e17f52d623cc146b7d9bf5a2e02965043508b4c4) --- llvm/lib/IR/Verifier.cpp | 4 ++++ .../Generic/2009-11-03-InsertExtractValue.ll | 2 +- llvm/test/Verifier/unique-disubprogram.ll | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Verifier/unique-disubprogram.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index f81e947dc94c2..2e9c2e4af90df 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2404,6 +2404,10 @@ void Verifier::visitFunction(const Function &F) { "function must have a single !dbg attachment", &F, I.second); AssertDI(isa(I.second), "function !dbg attachment must be a subprogram", &F, I.second); + AssertDI(cast(I.second)->isDistinct(), + "function definition may only have a distinct !dbg attachment", + &F); + auto *SP = cast(I.second); const Function *&AttachedTo = DISubprogramAttachments[SP]; AssertDI(!AttachedTo || AttachedTo == &F, diff --git a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll b/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll index 57ee7ebbb2cb3..81bb5f2457ed9 100644 --- a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll +++ b/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} diff --git a/llvm/test/Verifier/unique-disubprogram.ll b/llvm/test/Verifier/unique-disubprogram.ll new file mode 100644 index 0000000000000..b4789a9293f7b --- /dev/null +++ b/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) From fdfe9903f5a6f6e8bf25659f918d840eeb3a1f2a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 25 Sep 2020 10:26:35 -0700 Subject: [PATCH 2/5] Fix Assembler/disubprogram.ll after e17f52d623cc146b7d9bf5a2e02965043508b4c4 (cherry picked from commit 6caf3fb8178699ac14fb94fef99aaf1cf297264f) --- llvm/test/Assembler/disubprogram.ll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/test/Assembler/disubprogram.ll b/llvm/test/Assembler/disubprogram.ll index 10bd5520d84dc..6feb27ce48012 100644 --- a/llvm/test/Assembler/disubprogram.ll +++ b/llvm/test/Assembler/disubprogram.ll @@ -25,8 +25,8 @@ define void @_Z3foov() !dbg !9 { isOptimized: true, flags: "-O2", splitDebugFilename: "abc.debug", emissionKind: 2) -; CHECK: !9 = !DISubprogram(scope: null, spFlags: 0) -!9 = !DISubprogram(isDefinition: false) +; CHECK: !9 = distinct !DISubprogram(scope: null, spFlags: 0) +!9 = distinct !DISubprogram(isDefinition: false) ; CHECK: !10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, file: !2, line: 7, type: !3, scopeLine: 8, containingType: !4, virtualIndex: 10, thisAdjustment: 3, flags: DIFlagPrototyped | DIFlagNoReturn, spFlags: DISPFlagPureVirtual | DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, templateParams: !5, declaration: !9, retainedNodes: !6) !10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, From be39e9d01f6085b75ee343f781607da4a24d3024 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 25 Sep 2020 10:51:54 -0700 Subject: [PATCH 3/5] Revert "Add a verifier check that rejects non-distinct DISubprogram function" This reverts commit e17f52d623cc146b7d9bf5a2e02965043508b4c4. while investigating bot breakage. (cherry picked from commit 8055ae31f46b0a3fafd7b64f6cd77b78b34e6753) --- llvm/lib/IR/Verifier.cpp | 4 ---- .../Generic/2009-11-03-InsertExtractValue.ll | 2 +- llvm/test/Verifier/unique-disubprogram.ll | 16 ---------------- 3 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 llvm/test/Verifier/unique-disubprogram.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 2e9c2e4af90df..f81e947dc94c2 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2404,10 +2404,6 @@ void Verifier::visitFunction(const Function &F) { "function must have a single !dbg attachment", &F, I.second); AssertDI(isa(I.second), "function !dbg attachment must be a subprogram", &F, I.second); - AssertDI(cast(I.second)->isDistinct(), - "function definition may only have a distinct !dbg attachment", - &F); - auto *SP = cast(I.second); const Function *&AttachedTo = DISubprogramAttachments[SP]; AssertDI(!AttachedTo || AttachedTo == &F, diff --git a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll b/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll index 81bb5f2457ed9..57ee7ebbb2cb3 100644 --- a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll +++ b/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll @@ -3,7 +3,7 @@ !llvm.module.flags = !{!6} !llvm.dbg.cu = !{!5} -!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) +!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) !1 = !DIFile(filename: "/foo", directory: "bar.cpp") !2 = !DISubroutineType(types: !3) !3 = !{null} diff --git a/llvm/test/Verifier/unique-disubprogram.ll b/llvm/test/Verifier/unique-disubprogram.ll deleted file mode 100644 index b4789a9293f7b..0000000000000 --- a/llvm/test/Verifier/unique-disubprogram.ll +++ /dev/null @@ -1,16 +0,0 @@ -; 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) From 52f9998ca9c405e555cdd437b2b40a16a6881722 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 24 Sep 2020 16:59:36 -0700 Subject: [PATCH 4/5] 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 Thanks to Fangrui for fixing an assembler test I had missed! https://reviews.llvm.org/D88270 (cherry picked from commit 137597d4f47854bb1701f6883d5c91e8a14d29a2) --- llvm/lib/IR/Verifier.cpp | 4 ++++ .../Generic/2009-11-03-InsertExtractValue.ll | 2 +- llvm/test/Verifier/unique-disubprogram.ll | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Verifier/unique-disubprogram.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index f81e947dc94c2..2e9c2e4af90df 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2404,6 +2404,10 @@ void Verifier::visitFunction(const Function &F) { "function must have a single !dbg attachment", &F, I.second); AssertDI(isa(I.second), "function !dbg attachment must be a subprogram", &F, I.second); + AssertDI(cast(I.second)->isDistinct(), + "function definition may only have a distinct !dbg attachment", + &F); + auto *SP = cast(I.second); const Function *&AttachedTo = DISubprogramAttachments[SP]; AssertDI(!AttachedTo || AttachedTo == &F, diff --git a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll b/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll index 57ee7ebbb2cb3..81bb5f2457ed9 100644 --- a/llvm/test/DebugInfo/Generic/2009-11-03-InsertExtractValue.ll +++ b/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} diff --git a/llvm/test/Verifier/unique-disubprogram.ll b/llvm/test/Verifier/unique-disubprogram.ll new file mode 100644 index 0000000000000..b4789a9293f7b --- /dev/null +++ b/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) From 2875ec773d20ecf796a7e532532bdfc90c64ef94 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 25 Sep 2020 10:08:24 -0700 Subject: [PATCH 5/5] Fix DISubprogram-v4.ll after e17f52d623cc146b7d9bf5a2e02965043508b4c4 (cherry picked from commit 7d0556fc137aa07347741b7750e50ecbc2b4c6e2) --- llvm/test/Bitcode/DISubprogram-v4.ll | 4 ++-- llvm/test/Bitcode/DISubprogram-v4.ll.bc | Bin 1372 -> 1336 bytes 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/test/Bitcode/DISubprogram-v4.ll b/llvm/test/Bitcode/DISubprogram-v4.ll index ce5521002cafb..9e5caecd7361a 100644 --- a/llvm/test/Bitcode/DISubprogram-v4.ll +++ b/llvm/test/Bitcode/DISubprogram-v4.ll @@ -24,8 +24,8 @@ define void @_Z3foov() !dbg !9 { !8 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", file: !2, isOptimized: true, flags: "-O2") -; CHECK: !9 = !DISubprogram(scope: null, spFlags: 0) -!9 = !DISubprogram(isDefinition: false) +; CHECK: !9 = distinct !DISubprogram(scope: null, spFlags: 0) +!9 = distinct !DISubprogram(isDefinition: false) ; CHECK: !10 = distinct !DISubprogram({{.*}}, spFlags: DISPFlagPureVirtual | DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, !10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, diff --git a/llvm/test/Bitcode/DISubprogram-v4.ll.bc b/llvm/test/Bitcode/DISubprogram-v4.ll.bc index 392df4aae74d3fb0df0c2196191496a4eb4045dd..41bbcf874ac144ac97196fdf8d5e1300a91441b1 100644 GIT binary patch delta 473 zcmcb^wS&vh$@#!NQxOIRRt5%!Bpw45&&Ykx-d(oSbzw9D2{9=0Ffdp%GB9v6DKant z`N9(o4df??C^)-yEM<^1a$@o1n=n!FNPuHtW6#6pr(GiE@xcyc2{BI*j*l`< W%g-+}*E7&FuqiG{$;`6@s{sH{`fMZs delta 509 zcmdnNb%)E)$@#!NQxOIRRt5%!Bpw45pU8b`?=RcwhV}}uo&bs~@-Q&iF)}c4Gbu7K z0o902G&ImIIHIWRBGld^;5dmXC@!v0SUmYVQz7H6$(hUw^%|`UWupZcx)~T6nSn<7gz|bNW*iq|IUvN~@Bm~- zaAsio_qij zff>U9GzJVH#>7C)VL&oR8ez^E0S0DK2L*-$J}nF>2STPo^};BF!woW>JuGS(+}k&7 zGujlWrgPFHHE~W_^#YGsD^Bg2oWjzU*2s1Qs2t>~XqE(!7a0l_7#KhdBR&D87KYuR zXaIv)VBGKmSwhTH(m(?7QO0Tc`DGS*26_g?WqAtenI*br#>uHE7Dj0nmL@jEB`KMC Ic3`ax0J7bADF6Tf