[PATCH] D152194: [StaticAnalyzer] Fix nullptr dereference issue found by static analyzer tool

Soumi Manna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 28 20:40:59 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa806ec4857c2: [analyzer] Refactor codes in findMethodDecl() (authored by Manna).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152194/new/

https://reviews.llvm.org/D152194

Files:
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp


Index: clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -742,8 +742,6 @@
   const ObjCMethodDecl *Method = nullptr;
 
   QualType ReceiverType = MessageExpr->getReceiverType();
-  const auto *ReceiverObjectPtrType =
-      ReceiverType->getAs<ObjCObjectPointerType>();
 
   // Do this "devirtualization" on instance and class methods only. Trust the
   // static type on super and super class calls.
@@ -753,7 +751,8 @@
     // type, look up the method in the tracked type, not in the receiver type.
     // This way we preserve more information.
     if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType() ||
-        ASTCtxt.canAssignObjCInterfaces(ReceiverObjectPtrType, TrackedType)) {
+        ASTCtxt.canAssignObjCInterfaces(
+            ReceiverType->castAs<ObjCObjectPointerType>(), TrackedType)) {
       const ObjCInterfaceDecl *InterfaceDecl = TrackedType->getInterfaceDecl();
       // The method might not be found.
       Selector Sel = MessageExpr->getSelector();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152194.535614.patch
Type: text/x-patch
Size: 1206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230629/24699986/attachment.bin>


More information about the cfe-commits mailing list