[lldb][NFC] Refactor some IsClangType checks in ClangASTContext
authorRaphael Isemann <teemperor@gmail.com>
Fri, 8 Nov 2019 11:03:28 +0000 (12:03 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 8 Nov 2019 11:03:28 +0000 (12:03 +0100)
Summary:
All type in these functions need be valid and Clang types, so
we might as well replace these checks with IsClangType.

Also lets IsClangType explicitly check for validity instead of
assuming that the TypeSystem is a nullptr.

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70001

lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Symbol/ClangUtil.cpp

index 61b08ab9f516ada8f126d07b2a5cabcf8e9cff31..31b62ebb615e151701c878eb31560ba03d905cb1 100644 (file)
@@ -3601,7 +3601,7 @@ bool ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) {
 }
 
 bool ClangASTContext::IsObjCClassType(const CompilerType &type) {
-  if (type) {
+  if (ClangUtil::IsClangType(type)) {
     clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
 
     const clang::ObjCObjectPointerType *obj_pointer_type =
@@ -3886,7 +3886,7 @@ bool ClangASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) {
 
 bool ClangASTContext::IsObjCObjectPointerType(const CompilerType &type,
                                               CompilerType *class_type_ptr) {
-  if (!type)
+  if (!ClangUtil::IsClangType(type))
     return false;
 
   clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
index 86be895fadcbaebec4a8b3d5a84a0e806aca36dc..71ff36a5ebaba293b8f07821a78d6344bcecc082 100644 (file)
@@ -15,6 +15,10 @@ using namespace clang;
 using namespace lldb_private;
 
 bool ClangUtil::IsClangType(const CompilerType &ct) {
+  // Invalid types are never Clang types.
+  if (!ct)
+    return false;
+
   if (llvm::dyn_cast_or_null<ClangASTContext>(ct.GetTypeSystem()) == nullptr)
     return false;