[clang] ef865d1 - [clang] AddObjCKeyValueCompletions - use castAs<> instead of getAs<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 17 09:16:13 PDT 2022


Author: Simon Pilgrim
Date: 2022-03-17T16:16:01Z
New Revision: ef865d16ec3b8ce636786ed472ac28c977f2f304

URL: https://github.com/llvm/llvm-project/commit/ef865d16ec3b8ce636786ed472ac28c977f2f304
DIFF: https://github.com/llvm/llvm-project/commit/ef865d16ec3b8ce636786ed472ac28c977f2f304.diff

LOG: [clang] AddObjCKeyValueCompletions - use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointers are always dereferenced, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang/lib/Sema/SemaCodeComplete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 0c9bcf546da79..ba99f18996ada 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -9138,8 +9138,8 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,
   if (IsInstanceMethod &&
       (ReturnType.isNull() ||
        (ReturnType->isObjCObjectPointerType() &&
-        ReturnType->getAs<ObjCObjectPointerType>()->getInterfaceDecl() &&
-        ReturnType->getAs<ObjCObjectPointerType>()
+        ReturnType->castAs<ObjCObjectPointerType>()->getInterfaceDecl() &&
+        ReturnType->castAs<ObjCObjectPointerType>()
                 ->getInterfaceDecl()
                 ->getName() == "NSEnumerator"))) {
     std::string SelectorName = (Twine("enumeratorOf") + UpperKey).str();


        


More information about the cfe-commits mailing list