[clang] 6999335 - ObjCMethodDecl::findPropertyDecl - fix static analyzer null dereference warnings. NFCI.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 12 08:44:08 PDT 2020


Author: Simon Pilgrim
Date: 2020-03-12T15:36:49Z
New Revision: 69993350aeed08b6392f614c510697579302a39b

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

LOG: ObjCMethodDecl::findPropertyDecl  - fix static analyzer null dereference warnings. NFCI.

All paths dereference the ClassDecl pointer, so use a cast<> instead of dyn_cast<>, assert that its not null and remove the remaining null tests.

Added: 
    

Modified: 
    clang/lib/AST/DeclObjC.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index 9a84e3c4a510..6492f07eb5b0 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -1361,25 +1361,23 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
         return Found;
     } else {
       // Determine whether the container is a class.
-      ClassDecl = dyn_cast<ObjCInterfaceDecl>(Container);
+      ClassDecl = cast<ObjCInterfaceDecl>(Container);
     }
+    assert(ClassDecl && "Failed to find main class");
 
     // If we have a class, check its visible extensions.
-    if (ClassDecl) {
-      for (const auto *Ext : ClassDecl->visible_extensions()) {
-        if (Ext == Container)
-          continue;
-
-        if (const auto *Found = findMatchingProperty(Ext))
-          return Found;
-      }
+    for (const auto *Ext : ClassDecl->visible_extensions()) {
+      if (Ext == Container)
+        continue;
+      if (const auto *Found = findMatchingProperty(Ext))
+        return Found;
     }
 
     assert(isSynthesizedAccessorStub() && "expected an accessor stub");
+
     for (const auto *Cat : ClassDecl->known_categories()) {
       if (Cat == Container)
         continue;
-
       if (const auto *Found = findMatchingProperty(Cat))
         return Found;
     }


        


More information about the cfe-commits mailing list