Skip to content

Commit b390d8e

Browse files
committed
[IR/Verifier] Each DISubprogram with isDefinition: true must belong to a CU.
Add a check to catch violations. ~60 tests were broken and prevented this change to be committed. Adrian and I (thanks Adrian!) went through them in the last week or so updating. The check can be done more efficiently but I'd still like to get this in ASAP to avoid more broken tests to be checked in (if any). PR: 27101 llvm-svn: 266102
1 parent c394357 commit b390d8e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,22 @@ void Verifier::visitDISubprogram(const DISubprogram &N) {
10111011

10121012
if (N.isDefinition())
10131013
Assert(N.isDistinct(), "subprogram definitions must be distinct", &N);
1014+
1015+
// Ensure that every DISubprogram with isDefinition: true belongs
1016+
// to a DICompileUnit.
1017+
// FIXME: This is a very inefficient way of handling the problem.
1018+
// Use a SmallSetPtr which contains the Listed DISubprograms in the CU
1019+
// instead.
1020+
if (N.isDefinition()) {
1021+
auto *CUs = M->getNamedMetadata("llvm.dbg.cu");
1022+
Assert(CUs, "subprogram must belong to a compile unit", &N);
1023+
for (auto *CU : CUs->operands())
1024+
if (auto Subprograms = cast<DICompileUnit>(CU)->getSubprograms())
1025+
for (const auto *Sp : Subprograms)
1026+
if (Sp == &N)
1027+
return;
1028+
Assert(false, "subprogram not found in any compile unit", &N);
1029+
}
10141030
}
10151031

10161032
void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; Reject if DISubprogram does not belong to a DICompileUnit.
2+
; RUN: not llvm-as %s
3+
4+
@_ZZNK4llvm6object15MachOObjectFile21getRelocationTypeNameENS0_11DataRefImplERNS_15SmallVectorImplIcEEE5Table = external unnamed_addr constant [6 x i8*], align 16
5+
6+
!llvm.dbg.cu = !{!0}
7+
!llvm.module.flags = !{!13}
8+
9+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: 0, globals: !2, imports: !9)
10+
!1 = !DIFile(filename: "../lib/Object/MachOObjectFile.cpp", directory: "/home/davide/work/llvm/build-lto-debug")
11+
!2 = !{!3, !8}
12+
!3 = !DIGlobalVariable(name: "Table", scope: !4, isLocal: false, isDefinition: true, variable: [6 x i8*]* @_ZZNK4llvm6object15MachOObjectFile21getRelocationTypeNameENS0_11DataRefImplERNS_15SmallVectorImplIcEEE5Table)
13+
!4 = distinct !DILexicalBlock(scope: !5, line: 722, column: 23)
14+
!5 = distinct !DILexicalBlock(scope: !6, line: 721, column: 17)
15+
!6 = distinct !DISubprogram(name: "getRelocationTypeName", scope: null, isLocal: false, isDefinition: true, isOptimized: false, variables: !7)
16+
!7 = !{}
17+
!8 = !DIGlobalVariable(name: "IsLittleEndianHost", scope: null, isLocal: false, isDefinition: true, variable: i1 true)
18+
!9 = !{!10, !12}
19+
!10 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !11, line: 121)
20+
!11 = !DINamespace(name: "std", scope: null, line: 1967)
21+
!12 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, line: 32)
22+
!13 = !{i32 2, !"Debug Info Version", i32 3}

0 commit comments

Comments
 (0)