Fix a crash, an UB and add some assert to dwo symbol file handling

llvm-svn: 249827
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index cbd31a5..1c1369a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -772,6 +772,10 @@
                             // will automatically call the SymbolFile virtual function
                             // "SymbolFileDWARF::CompleteType(Type *)"
                             // When the definition needs to be defined.
+                            assert(!dwarf->GetForwardDeclClangTypeToDie().count(ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()) &&
+                                   "Type already in the forward declaration map!");
+                            assert(((SymbolFileDWARF*)m_ast.GetSymbolFile())->UserIDMatches(die.GetDIERef().GetUID()) &&
+                                   "Adding incorrect type to forward declaration map");
                             dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = clang_type.GetOpaqueQualType();
                             dwarf->GetForwardDeclClangTypeToDie()[ClangASTContext::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] = die.GetDIERef();
                             m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), true);
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 5b2de70..e9cbd8c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1555,6 +1555,8 @@
     DWARFDebugInfo* debug_info = DebugInfo();
     DWARFDIE dwarf_die = debug_info->GetDIE(die_it->getSecond());
 
+    assert(UserIDMatches(die_it->getSecond().GetUID()) && "CompleteType called on the wrong SymbolFile");
+
     // Once we start resolving this type, remove it from the forward declaration
     // map in case anyone child members or other types require this type to get resolved.
     // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
index ba6b580..60c281c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
@@ -125,3 +125,9 @@
 {
     return DWARFExpression::SplitDwarfLocationList;
 }
+
+TypeSystem*
+SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language)
+{
+    return GetBaseSymbolFile()->GetTypeSystemForLanguage(language);
+}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
index 3a65509..8214496 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
@@ -41,6 +41,9 @@
     lldb_private::DWARFExpression::LocationListFormat
     GetLocationListFormat() const override;
 
+    lldb_private::TypeSystem*
+    GetTypeSystemForLanguage(lldb::LanguageType language) override;
+
 protected:
     DIEToTypePtr&
     GetDIEToType() override;
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 6d61c86..2ffb6d6 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -2593,14 +2593,16 @@
     {
         default:
             break;
-            
+
         case clang::Type::ConstantArray:
             if (element_type_ptr)
                 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType());
             if (size)
                 *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX);
+            if (is_incomplete)
+                *is_incomplete = false;
             return true;
-            
+
         case clang::Type::IncompleteArray:
             if (element_type_ptr)
                 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType());
@@ -2609,21 +2611,25 @@
             if (is_incomplete)
                 *is_incomplete = true;
             return true;
-            
+
         case clang::Type::VariableArray:
             if (element_type_ptr)
                 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType());
             if (size)
                 *size = 0;
+            if (is_incomplete)
+                *is_incomplete = false;
             return true;
-            
+
         case clang::Type::DependentSizedArray:
             if (element_type_ptr)
                 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType());
             if (size)
                 *size = 0;
+            if (is_incomplete)
+                *is_incomplete = false;
             return true;
-            
+
         case clang::Type::Typedef:
             return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
                                element_type_ptr,