///
/// \see lldb_private::TypeSystemClang::GetType(clang::QualType)
CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type)
- : m_type(type), m_type_system(type_system) {}
+ : m_type(type), m_type_system(type_system) {
+ assert(Verify() && "verification failed");
+ }
CompilerType(const CompilerType &rhs)
: m_type(rhs.m_type), m_type_system(rhs.m_type_system) {}
}
private:
+#ifndef NDEBUG
+ /// If the type is valid, ask the TypeSystem to verify the integrity
+ /// of the type to catch CompilerTypes that mix and match invalid
+ /// TypeSystem/Opaque type pairs.
+ bool Verify() const;
+#endif
+
lldb::opaque_compiler_type_t m_type = nullptr;
TypeSystem *m_type_system = nullptr;
};
void *other_opaque_decl_ctx) = 0;
// Tests
+#ifndef NDEBUG
+ /// Verify the integrity of the type to catch CompilerTypes that mix
+ /// and match invalid TypeSystem/Opaque type pairs.
+ virtual bool Verify(lldb::opaque_compiler_type_t type) = 0;
+#endif
virtual bool IsArrayType(lldb::opaque_compiler_type_t type,
CompilerType *element_type, uint64_t *size,
// Tests
+#ifndef NDEBUG
+bool TypeSystemClang::Verify(lldb::opaque_compiler_type_t type) {
+ return !type || llvm::isa<clang::Type>(GetQualType(type).getTypePtr());
+}
+#endif
+
bool TypeSystemClang::IsAggregateType(lldb::opaque_compiler_type_t type) {
clang::QualType qual_type(RemoveWrappingTypes(GetCanonicalQualType(type)));
// Tests
+#ifndef NDEBUG
+ bool Verify(lldb::opaque_compiler_type_t type) override;
+#endif
+
bool IsArrayType(lldb::opaque_compiler_type_t type,
CompilerType *element_type, uint64_t *size,
bool *is_incomplete) override;
return false;
}
+#ifndef NDEBUG
+bool CompilerType::Verify() const {
+ return !IsValid() || m_type_system->Verify(m_type);
+}
+#endif
+
bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
const lldb_private::CompilerType &rhs) {
return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
return CreateInstanceHelper(language, nullptr, target);
}
+#ifndef NDEBUG
+bool TypeSystem::Verify(lldb::opaque_compiler_type_t type) { return true; }
+#endif
+
bool TypeSystem::IsAnonymousType(lldb::opaque_compiler_type_t type) {
return false;
}