Skip to content

Commit 69984e8

Browse files
Merge pull request #1849 from adrian-prantl/69534688
Add a verifier check that rejects non-distinct DISubprogram function
2 parents 6ffed6e + 2875ec7 commit 69984e8

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,10 @@ void Verifier::visitFunction(const Function &F) {
24042404
"function must have a single !dbg attachment", &F, I.second);
24052405
AssertDI(isa<DISubprogram>(I.second),
24062406
"function !dbg attachment must be a subprogram", &F, I.second);
2407+
AssertDI(cast<DISubprogram>(I.second)->isDistinct(),
2408+
"function definition may only have a distinct !dbg attachment",
2409+
&F);
2410+
24072411
auto *SP = cast<DISubprogram>(I.second);
24082412
const Function *&AttachedTo = DISubprogramAttachments[SP];
24092413
AssertDI(!AttachedTo || AttachedTo == &F,

llvm/test/Assembler/disubprogram.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ define void @_Z3foov() !dbg !9 {
2525
isOptimized: true, flags: "-O2",
2626
splitDebugFilename: "abc.debug", emissionKind: 2)
2727

28-
; CHECK: !9 = !DISubprogram(scope: null, spFlags: 0)
29-
!9 = !DISubprogram(isDefinition: false)
28+
; CHECK: !9 = distinct !DISubprogram(scope: null, spFlags: 0)
29+
!9 = distinct !DISubprogram(isDefinition: false)
3030

3131
; 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)
3232
!10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,

llvm/test/Bitcode/DISubprogram-v4.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ define void @_Z3foov() !dbg !9 {
2424
!8 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
2525
file: !2, isOptimized: true, flags: "-O2")
2626

27-
; CHECK: !9 = !DISubprogram(scope: null, spFlags: 0)
28-
!9 = !DISubprogram(isDefinition: false)
27+
; CHECK: !9 = distinct !DISubprogram(scope: null, spFlags: 0)
28+
!9 = distinct !DISubprogram(isDefinition: false)
2929

3030
; CHECK: !10 = distinct !DISubprogram({{.*}}, spFlags: DISPFlagPureVirtual | DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized,
3131
!10 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
-36 Bytes
Binary file not shown.

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)