[llvm] r233657 - Verifier: Move more debug info checks away from Verify()

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Mar 30 18:28:22 PDT 2015


Author: dexonsmith
Date: Mon Mar 30 20:28:22 2015
New Revision: 233657

URL: http://llvm.org/viewvc/llvm-project?rev=233657&view=rev
Log:
Verifier: Move more debug info checks away from Verify()

Most of these checks were already in the `Verifier` so this is more of a
cleanup.  Now almost everything is over there.

Now that require a `name:` for `MDGlobalVariable`, add a check in
`LLParser` for it.

Added:
    llvm/trunk/test/Assembler/invalid-mdglobalvariable-empty-name.ll
    llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll
Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/lib/IR/Verifier.cpp
    llvm/trunk/test/Assembler/mdglobalvariable.ll

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=233657&r1=233656&r2=233657&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Mar 30 20:28:22 2015
@@ -3041,7 +3041,9 @@ struct MDConstant : public MDFieldImpl<C
   MDConstant() : ImplTy(nullptr) {}
 };
 struct MDStringField : public MDFieldImpl<MDString *> {
-  MDStringField() : ImplTy(nullptr) {}
+  bool AllowEmpty;
+  MDStringField(bool AllowEmpty = true)
+      : ImplTy(nullptr), AllowEmpty(AllowEmpty) {}
 };
 struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
   MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
@@ -3253,10 +3255,14 @@ bool LLParser::ParseMDField(LocTy Loc, S
 
 template <>
 bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
+  LocTy ValueLoc = Lex.getLoc();
   std::string S;
   if (ParseStringConstant(S))
     return true;
 
+  if (!Result.AllowEmpty && S.empty())
+    return Error(ValueLoc, "'" + Name + "' cannot be empty");
+
   Result.assign(S.empty() ? nullptr : MDString::get(Context, S));
   return false;
 }
@@ -3655,8 +3661,8 @@ bool LLParser::ParseMDTemplateValueParam
 ///                         declaration: !3)
 bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) {
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
+  REQUIRED(name, MDStringField, (/* AllowEmpty */ false));                     \
   OPTIONAL(scope, MDField, );                                                  \
-  OPTIONAL(name, MDStringField, );                                             \
   OPTIONAL(linkageName, MDStringField, );                                      \
   OPTIONAL(file, MDField, );                                                   \
   OPTIONAL(line, LineField, );                                                 \

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=233657&r1=233656&r2=233657&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Mar 30 20:28:22 2015
@@ -275,16 +275,6 @@ bool DISubprogram::Verify() const {
   if (!N)
     return false;
 
-  if (!isScopeRef(N->getScope()))
-    return false;
-
-  if (auto *Op = N->getType())
-    if (!isa<MDNode>(Op))
-      return false;
-
-  if (!isTypeRef(getContainingType()))
-    return false;
-
   if (isLValueReference() && isRValueReference())
     return false;
 
@@ -315,38 +305,8 @@ bool DISubprogram::Verify() const {
   return true;
 }
 
-bool DIGlobalVariable::Verify() const {
-  auto *N = dyn_cast_or_null<MDGlobalVariable>(DbgNode);
-
-  if (!N)
-    return false;
-
-  if (N->getDisplayName().empty())
-    return false;
-
-  if (auto *Op = N->getScope())
-    if (!isa<MDNode>(Op))
-      return false;
-
-  if (auto *Op = N->getStaticDataMemberDeclaration())
-    if (!isa<MDNode>(Op))
-      return false;
-
-  return isTypeRef(N->getType());
-}
-
-bool DIVariable::Verify() const {
-  auto *N = dyn_cast_or_null<MDLocalVariable>(DbgNode);
-
-  if (!N)
-    return false;
-
-  if (auto *Op = N->getScope())
-    if (!isa<MDNode>(Op))
-      return false;
-
-  return isTypeRef(N->getType());
-}
+bool DIGlobalVariable::Verify() const { return isGlobalVariable(); }
+bool DIVariable::Verify() const { return isVariable(); }
 
 bool DILocation::Verify() const {
   return dyn_cast_or_null<MDLocation>(DbgNode);

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=233657&r1=233656&r2=233657&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Mon Mar 30 20:28:22 2015
@@ -969,6 +969,7 @@ void Verifier::visitMDGlobalVariable(con
   visitMDVariable(N);
 
   Assert(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
+  Assert(!N.getName().empty(), "missing global variable name", &N);
   if (auto *V = N.getRawVariable()) {
     Assert(isa<ConstantAsMetadata>(V) &&
                !isa<Function>(cast<ConstantAsMetadata>(V)->getValue()),

Added: llvm/trunk/test/Assembler/invalid-mdglobalvariable-empty-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdglobalvariable-empty-name.ll?rev=233657&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdglobalvariable-empty-name.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdglobalvariable-empty-name.ll Mon Mar 30 20:28:22 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:30: error: 'name' cannot be empty
+!0 = !MDGlobalVariable(name: "")

Added: llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll?rev=233657&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll (added)
+++ llvm/trunk/test/Assembler/invalid-mdglobalvariable-missing-name.ll Mon Mar 30 20:28:22 2015
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:24: error: missing required field 'name'
+!0 = !MDGlobalVariable()

Modified: llvm/trunk/test/Assembler/mdglobalvariable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/mdglobalvariable.ll?rev=233657&r1=233656&r2=233657&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/mdglobalvariable.ll (original)
+++ llvm/trunk/test/Assembler/mdglobalvariable.ll Mon Mar 30 20:28:22 2015
@@ -17,8 +17,8 @@
                        file: !2, line: 7, type: !3, isLocal: true,
                        isDefinition: false, variable: i32* @foo)
 
-; CHECK: !6 = !MDGlobalVariable(scope: !0, isLocal: false, isDefinition: true)
-!6 = !MDGlobalVariable(scope: !0)
+; CHECK: !6 = !MDGlobalVariable(name: "foo", scope: !0, isLocal: false, isDefinition: true)
+!6 = !MDGlobalVariable(name: "foo", scope: !0)
 
 !7 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Class", size: 8, align: 8)
 !8 = !MDDerivedType(tag: DW_TAG_member, name: "mem", flags: DIFlagStaticMember, scope: !7, baseType: !3)





More information about the llvm-commits mailing list