Skip to content

Commit edee6db

Browse files
author
davide
committed
[Verifier] Stop accepting broken DIGlobalVariable(s).
The code wasn't yelling at the user when there's a reference from a DIGlobalVariableExpression. Thanks to Adrian for the reduced testcase. Fixes PR34672. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314069 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 448196a commit edee6db

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

lib/IR/Verifier.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ void Verifier::visitDITemplateValueParameter(
11461146
void Verifier::visitDIVariable(const DIVariable &N) {
11471147
if (auto *S = N.getRawScope())
11481148
AssertDI(isa<DIScope>(S), "invalid scope", &N, S);
1149-
AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
11501149
if (auto *F = N.getRawFile())
11511150
AssertDI(isa<DIFile>(F), "invalid file", &N, F);
11521151
}
@@ -1169,6 +1168,7 @@ void Verifier::visitDILocalVariable(const DILocalVariable &N) {
11691168
// Checks common to all variables.
11701169
visitDIVariable(N);
11711170

1171+
AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
11721172
AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
11731173
AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),
11741174
"local variable requires a valid scope", &N, N.getRawScope());
@@ -1181,6 +1181,8 @@ void Verifier::visitDIExpression(const DIExpression &N) {
11811181
void Verifier::visitDIGlobalVariableExpression(
11821182
const DIGlobalVariableExpression &GVE) {
11831183
AssertDI(GVE.getVariable(), "missing variable");
1184+
if (auto *Var = GVE.getVariable())
1185+
visitDIGlobalVariable(*Var);
11841186
if (auto *Expr = GVE.getExpression()) {
11851187
visitDIExpression(*Expr);
11861188
if (auto Fragment = Expr->getFragmentInfo())

test/DebugInfo/pr34186.ll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
; Make sure we reject GVs without a type and we verify each exactly once.
1+
; Make sure we reject GVs without a type.
2+
; Currently the verifier when traversing the graph induced by the debug info
3+
; metadata can reach the GV both from a DICompileUnit and a DIGlobalVariable
4+
; expression, so we emit a diagnostic twice. This is, not ideal, but the
5+
; alternative is that of keeping a map of visited GVs, which has non trivial
6+
; memory usage consequences on large testcases, or when LTO is the mode of
7+
; operation.
28
; RUN: not llc %s 2>&1 | FileCheck %s
39
; CHECK: missing global variable type
4-
; CHECK-NOT: missing global variable type
10+
; CHECK: missing global variable type
511

612
!llvm.dbg.cu = !{!2}
713
!llvm.module.flags = !{!63, !64}

test/DebugInfo/pr34672.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not opt -verify %s 2>&1 | FileCheck %s
2+
; CHECK: invalid type ref
3+
; CHECK-NOT: invalid type ref
4+
5+
@global = common global i32 0, align 4, !dbg !2
6+
7+
!llvm.dbg.cu = !{!0}
8+
!llvm.module.flags = !{!5, !6}
9+
10+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "adrian", emissionKind: FullDebug)
11+
!1 = !DIFile(filename: "broken.c", directory: "/")
12+
!2 = !DIGlobalVariableExpression(var: !3, expr: !DIExpression())
13+
!3 = !DIGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !1, isLocal: false, isDefinition: true)
14+
!5 = !{i32 2, !"Dwarf Version", i32 4}
15+
!6 = !{i32 1, !"Debug Info Version", i32 3}
16+

0 commit comments

Comments
 (0)