Skip to content

Add a verifier check that rejects non-distinct DISubprogram function #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,10 @@ void Verifier::visitFunction(const Function &F) {
"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,
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Assembler/disubprogram.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Bitcode/DISubprogram-v4.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file modified llvm/test/Bitcode/DISubprogram-v4.ll.bc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Verifier/unique-disubprogram.ll
Original file line number Diff line number Diff line change
@@ -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)