[clang] a806ec4 - [analyzer] Refactor codes in findMethodDecl()

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 28 20:40:55 PDT 2023


Author: Manna, Soumi
Date: 2023-06-28T20:40:02-07:00
New Revision: a806ec4857c2c662c89755edba56d893ae1beeb4

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

LOG: [analyzer] Refactor codes in findMethodDecl()

In findMethodDecl(clang::ObjCMessageExpr const *, clang::ObjCObjectPointerType const *, clang::ASTContext &), if the MessageExpr->getReceiverKind() is not Instance or Class, we never dereference pointer “ReceiverObjectPtrType”. Also, we don't dereference the pointer “ReceiverObjectPtrType” if ReceiverType is ObjCIdType or ObhjCClassType. So the pointer “ReceiverObjectPtrType”is only used in this branch and the declaration should be here.

This patch directly uses ReceiverType->castAs<ObjCObjectPointerType>() instead of ReceiverObjectPtrType when calling canAssignObjCInterfaces() to express the intent more clearly.

Reviewed By: erichkeane, steakhal

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index 6f26842e62c78..26f82fb67472b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -742,8 +742,6 @@ findMethodDecl(const ObjCMessageExpr *MessageExpr,
   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 @@ findMethodDecl(const ObjCMessageExpr *MessageExpr,
     // 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();


        


More information about the cfe-commits mailing list