[llvm] r314069 - [Verifier] Stop accepting broken DIGlobalVariable(s).

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 23 18:06:35 PDT 2017


Author: davide
Date: Sat Sep 23 18:06:35 2017
New Revision: 314069

URL: http://llvm.org/viewvc/llvm-project?rev=314069&view=rev
Log:
[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.

Added:
    llvm/trunk/test/DebugInfo/pr34672.ll
Modified:
    llvm/trunk/lib/IR/Verifier.cpp
    llvm/trunk/test/DebugInfo/pr34186.ll

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=314069&r1=314068&r2=314069&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Sat Sep 23 18:06:35 2017
@@ -1146,7 +1146,6 @@ void Verifier::visitDITemplateValueParam
 void Verifier::visitDIVariable(const DIVariable &N) {
   if (auto *S = N.getRawScope())
     AssertDI(isa<DIScope>(S), "invalid scope", &N, S);
-  AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
   if (auto *F = N.getRawFile())
     AssertDI(isa<DIFile>(F), "invalid file", &N, F);
 }
@@ -1169,6 +1168,7 @@ void Verifier::visitDILocalVariable(cons
   // Checks common to all variables.
   visitDIVariable(N);
 
+  AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
   AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
   AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),
            "local variable requires a valid scope", &N, N.getRawScope());
@@ -1181,6 +1181,8 @@ void Verifier::visitDIExpression(const D
 void Verifier::visitDIGlobalVariableExpression(
     const DIGlobalVariableExpression &GVE) {
   AssertDI(GVE.getVariable(), "missing variable");
+  if (auto *Var = GVE.getVariable())
+    visitDIGlobalVariable(*Var);
   if (auto *Expr = GVE.getExpression()) {
     visitDIExpression(*Expr);
     if (auto Fragment = Expr->getFragmentInfo())

Modified: llvm/trunk/test/DebugInfo/pr34186.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/pr34186.ll?rev=314069&r1=314068&r2=314069&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/pr34186.ll (original)
+++ llvm/trunk/test/DebugInfo/pr34186.ll Sat Sep 23 18:06:35 2017
@@ -1,7 +1,13 @@
-; Make sure we reject GVs without a type and we verify each exactly once.
+; Make sure we reject GVs without a type.
+; Currently the verifier when traversing the graph induced by the debug info
+; metadata can reach the GV both from a DICompileUnit and a DIGlobalVariable
+; expression, so we emit a diagnostic twice. This is, not ideal, but the
+; alternative is that of keeping a map of visited GVs, which has non trivial
+; memory usage consequences on large testcases, or when LTO is the mode of
+; operation.
 ; RUN: not llc %s 2>&1 | FileCheck %s
 ; CHECK: missing global variable type
-; CHECK-NOT: missing global variable type
+; CHECK: missing global variable type
 
 !llvm.dbg.cu = !{!2}
 !llvm.module.flags = !{!63, !64}

Added: llvm/trunk/test/DebugInfo/pr34672.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/pr34672.ll?rev=314069&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/pr34672.ll (added)
+++ llvm/trunk/test/DebugInfo/pr34672.ll Sat Sep 23 18:06:35 2017
@@ -0,0 +1,16 @@
+; RUN: not opt -verify %s 2>&1 | FileCheck %s
+; CHECK: invalid type ref
+; CHECK-NOT: invalid type ref
+
+ at global = common global i32 0, align 4, !dbg !2
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "adrian", emissionKind: FullDebug)
+!1 = !DIFile(filename: "broken.c", directory: "/")
+!2 = !DIGlobalVariableExpression(var: !3, expr: !DIExpression())
+!3 = !DIGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !1, isLocal: false, isDefinition: true)
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 1, !"Debug Info Version", i32 3}
+




More information about the llvm-commits mailing list