Silence sign compare warning. NFC.
[oota-llvm.git] / lib / IR / DebugInfo.cpp
index 3db74fcee58ef90fdcd6c2f24a8a0d43766742fb..9a6b9536bc1bdfd3917fc035ce59b3d7a4c36124 100644 (file)
@@ -92,7 +92,7 @@ bool DIDescriptor::Verify() const {
           DIObjCProperty(DbgNode).Verify() ||
           DITemplateTypeParameter(DbgNode).Verify() ||
           DITemplateValueParameter(DbgNode).Verify() ||
-          DIImportedEntity(DbgNode).Verify() || DIExpression(DbgNode).Verify());
+          DIImportedEntity(DbgNode).Verify());
 }
 
 static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
@@ -260,42 +260,48 @@ static bool isDescriptorRef(const Metadata *MD) {
 #endif
 
 bool DIType::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDType>(DbgNode);
   if (!N)
     return false;
   if (!isScopeRef(N->getScope()))
     return false;
 
-  // FIXME: Sink this into the various subclass verifies.
-  uint16_t Tag = getTag();
-  if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
-      Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
-      Tag != dwarf::DW_TAG_ptr_to_member_type &&
-      Tag != dwarf::DW_TAG_reference_type &&
-      Tag != dwarf::DW_TAG_rvalue_reference_type &&
-      Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_array_type &&
-      Tag != dwarf::DW_TAG_enumeration_type &&
-      Tag != dwarf::DW_TAG_subroutine_type &&
-      Tag != dwarf::DW_TAG_inheritance && Tag != dwarf::DW_TAG_friend &&
-      getFilename().empty())
-    return false;
-
   // DIType is abstract, it should be a BasicType, a DerivedType or
   // a CompositeType.
   if (isBasicType())
     return DIBasicType(DbgNode).Verify();
-  else if (isCompositeType())
+
+  // FIXME: Sink this into the various subclass verifies.
+  if (getFilename().empty()) {
+    // Check whether the filename is allowed to be empty.
+    uint16_t Tag = getTag();
+    if (Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
+        Tag != dwarf::DW_TAG_pointer_type &&
+        Tag != dwarf::DW_TAG_ptr_to_member_type &&
+        Tag != dwarf::DW_TAG_reference_type &&
+        Tag != dwarf::DW_TAG_rvalue_reference_type &&
+        Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_array_type &&
+        Tag != dwarf::DW_TAG_enumeration_type &&
+        Tag != dwarf::DW_TAG_subroutine_type &&
+        Tag != dwarf::DW_TAG_inheritance && Tag != dwarf::DW_TAG_friend &&
+        Tag != dwarf::DW_TAG_structure_type && Tag != dwarf::DW_TAG_member &&
+        Tag != dwarf::DW_TAG_typedef)
+      return false;
+  }
+
+  if (isCompositeType())
     return DICompositeType(DbgNode).Verify();
-  else if (isDerivedType())
+  if (isDerivedType())
     return DIDerivedType(DbgNode).Verify();
-  else
-    return false;
+  return false;
 }
 
-bool DIBasicType::Verify() const { return getRaw(); }
+bool DIBasicType::Verify() const {
+  return dyn_cast_or_null<MDBasicType>(DbgNode);
+}
 
 bool DIDerivedType::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDDerivedTypeBase>(DbgNode);
   if (!N)
     return false;
   if (getTag() == dwarf::DW_TAG_ptr_to_member_type) {
@@ -309,13 +315,13 @@ bool DIDerivedType::Verify() const {
 }
 
 bool DICompositeType::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDCompositeTypeBase>(DbgNode);
   return N && isTypeRef(N->getBaseType()) && isTypeRef(N->getVTableHolder()) &&
          !(isLValueReference() && isRValueReference());
 }
 
 bool DISubprogram::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDSubprogram>(DbgNode);
   if (!N)
     return false;
 
@@ -368,7 +374,7 @@ bool DISubprogram::Verify() const {
 }
 
 bool DIGlobalVariable::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDGlobalVariable>(DbgNode);
 
   if (!N)
     return false;
@@ -388,7 +394,7 @@ bool DIGlobalVariable::Verify() const {
 }
 
 bool DIVariable::Verify() const {
-  auto *N = getRaw();
+  auto *N = dyn_cast_or_null<MDLocalVariable>(DbgNode);
 
   if (!N)
     return false;
@@ -400,25 +406,37 @@ bool DIVariable::Verify() const {
   return isTypeRef(N->getType());
 }
 
-bool DIExpression::Verify() const {
-  // FIXME: This should return false if it's null!
-  auto *N = getRaw();
-  return !N || N->isValid();
+bool DILocation::Verify() const {
+  return dyn_cast_or_null<MDLocation>(DbgNode);
+}
+bool DINameSpace::Verify() const {
+  return dyn_cast_or_null<MDNamespace>(DbgNode);
+}
+bool DIFile::Verify() const { return dyn_cast_or_null<MDFile>(DbgNode); }
+bool DIEnumerator::Verify() const {
+  return dyn_cast_or_null<MDEnumerator>(DbgNode);
+}
+bool DISubrange::Verify() const {
+  return dyn_cast_or_null<MDSubrange>(DbgNode);
+}
+bool DILexicalBlock::Verify() const {
+  return dyn_cast_or_null<MDLexicalBlock>(DbgNode);
+}
+bool DILexicalBlockFile::Verify() const {
+  return dyn_cast_or_null<MDLexicalBlockFile>(DbgNode);
+}
+bool DITemplateTypeParameter::Verify() const {
+  return dyn_cast_or_null<MDTemplateTypeParameter>(DbgNode);
+}
+bool DITemplateValueParameter::Verify() const {
+  return dyn_cast_or_null<MDTemplateValueParameter>(DbgNode);
+}
+bool DIImportedEntity::Verify() const {
+  return dyn_cast_or_null<MDImportedEntity>(DbgNode);
 }
-
-bool DILocation::Verify() const { return getRaw(); }
-bool DINameSpace::Verify() const { return getRaw(); }
-bool DIFile::Verify() const { return getRaw(); }
-bool DIEnumerator::Verify() const { return getRaw(); }
-bool DISubrange::Verify() const { return getRaw(); }
-bool DILexicalBlock::Verify() const { return getRaw(); }
-bool DILexicalBlockFile::Verify() const { return getRaw(); }
-bool DITemplateTypeParameter::Verify() const { return getRaw(); }
-bool DITemplateValueParameter::Verify() const { return getRaw(); }
-bool DIImportedEntity::Verify() const { return getRaw(); }
 
 void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
-  TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
+  TypedTrackingMDRef<MDCompositeTypeBase> N(get());
   if (Elements)
     N->replaceElements(cast<MDTuple>(Elements));
   if (TParams)
@@ -436,7 +454,7 @@ DIScopeRef DIScope::getRef() const {
 }
 
 void DICompositeType::setContainingType(DICompositeType ContainingType) {
-  TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
+  TypedTrackingMDRef<MDCompositeTypeBase> N(get());
   N->replaceVTableHolder(ContainingType.getRef());
   DbgNode = N;
 }
@@ -451,7 +469,7 @@ bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
 }
 
 Function *DISubprogram::getFunction() const {
-  if (auto *N = getRaw())
+  if (auto *N = get())
     if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getFunction()))
       return dyn_cast<Function>(C->getValue());
   return nullptr;
@@ -508,26 +526,25 @@ StringRef DIScope::getName() const {
 }
 
 StringRef DIScope::getFilename() const {
-  if (auto *N = getRaw())
+  if (auto *N = get())
     return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 0);
   return "";
 }
 
 StringRef DIScope::getDirectory() const {
-  if (auto *N = getRaw())
+  if (auto *N = get())
     return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 1);
   return "";
 }
 
 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
   assert(Verify() && "Expected compile unit");
-  getRaw()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
+  get()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
 }
 
 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
   assert(Verify() && "Expected compile unit");
-  getRaw()->replaceGlobalVariables(
-      cast_or_null<MDTuple>(GlobalVariables.get()));
+  get()->replaceGlobalVariables(cast_or_null<MDTuple>(GlobalVariables.get()));
 }
 
 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
@@ -678,6 +695,8 @@ void DebugInfoFinder::processModule(const Module &M) {
       DIArray Imports = CU.getImportedEntities();
       for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
         DIImportedEntity Import = DIImportedEntity(Imports.getElement(i));
+        if (!Import)
+          continue;
         DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap);
         if (Entity.isType())
           processType(DIType(Entity));