r350861 - [analyzer] [RetainCountChecker] Remove redundant enum UnarySummaryKind

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 10 10:14:38 PST 2019


Author: george.karpenkov
Date: Thu Jan 10 10:14:38 2019
New Revision: 350861

URL: http://llvm.org/viewvc/llvm-project?rev=350861&view=rev
Log:
[analyzer] [RetainCountChecker] Remove redundant enum UnarySummaryKind

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

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
    cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h?rev=350861&r1=350860&r2=350861&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h Thu Jan 10 10:14:38 2019
@@ -537,10 +537,8 @@ class RetainSummaryManager {
   /// Free the OS object.
   const RetainSummary *getOSSummaryFreeRule(const FunctionDecl *FD);
 
-  enum UnaryFuncKind { cfretain, cfrelease, cfautorelease, cfmakecollectable };
-
   const RetainSummary *getUnarySummary(const FunctionType* FT,
-                                       UnaryFuncKind func);
+                                       ArgEffectKind AE);
 
   const RetainSummary *getCFSummaryCreateRule(const FunctionDecl *FD);
   const RetainSummary *getCFSummaryGetRule(const FunctionDecl *FD);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp?rev=350861&r1=350860&r2=350861&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp Thu Jan 10 10:14:38 2019
@@ -194,7 +194,7 @@ const RetainSummary *RetainSummaryManage
   } else if(FName == "NSMakeCollectable") {
     // Handle: id NSMakeCollectable(CFTypeRef)
     AllowAnnotations = false;
-    return RetTy->isObjCIdType() ? getUnarySummary(FT, cfmakecollectable)
+    return RetTy->isObjCIdType() ? getUnarySummary(FT, DoNothing)
                                  : getPersistentStopSummary();
   } else if (FName == "CMBufferQueueDequeueAndRetain" ||
              FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
@@ -307,16 +307,16 @@ const RetainSummary *RetainSummaryManage
         // We want to ignore such annotation.
         AllowAnnotations = false;
 
-        return getUnarySummary(FT, cfretain);
+        return getUnarySummary(FT, IncRef);
       } else if (isAutorelease(FD, FName)) {
         // The headers use cf_consumed, but we can fully model CFAutorelease
         // ourselves.
         AllowAnnotations = false;
 
-        return getUnarySummary(FT, cfautorelease);
+        return getUnarySummary(FT, Autorelease);
       } else if (isMakeCollectable(FName)) {
         AllowAnnotations = false;
-        return getUnarySummary(FT, cfmakecollectable);
+        return getUnarySummary(FT, DoNothing);
       } else {
         return getCFCreateGetRuleSummary(FD);
       }
@@ -326,7 +326,7 @@ const RetainSummary *RetainSummaryManage
     if (cocoa::isRefType(RetTy, "CG", FName) ||
         cocoa::isRefType(RetTy, "CV", FName)) {
       if (isRetain(FD, FName))
-        return getUnarySummary(FT, cfretain);
+        return getUnarySummary(FT, IncRef);
       else
         return getCFCreateGetRuleSummary(FD);
     }
@@ -350,7 +350,7 @@ const RetainSummary *RetainSummaryManage
     FName = FName.substr(FName.startswith("CGCF") ? 4 : 2);
 
     if (isRelease(FD, FName))
-      return getUnarySummary(FT, cfrelease);
+      return getUnarySummary(FT, DecRef);
     else {
       assert(ScratchArgs.isEmpty());
       // Remaining CoreFoundation and CoreGraphics functions.
@@ -644,11 +644,9 @@ RetainSummaryManager::canEval(const Call
   return None;
 }
 
-// TODO: UnaryFuncKind is a very funny enum, it really should not exist:
-// just pass the needed effect directly!
 const RetainSummary *
 RetainSummaryManager::getUnarySummary(const FunctionType* FT,
-                                      UnaryFuncKind func) {
+                                      ArgEffectKind AE) {
 
   // Unary functions have no arg effects by definition.
   ArgEffects ScratchArgs(AF.getEmptyMap());
@@ -659,13 +657,7 @@ RetainSummaryManager::getUnarySummary(co
   if (!FTP || FTP->getNumParams() != 1)
     return getPersistentStopSummary();
 
-  ArgEffect Effect(DoNothing, ObjKind::CF);
-  switch (func) {
-  case cfretain: Effect = Effect.withKind(IncRef); break;
-  case cfrelease: Effect = Effect.withKind(DecRef); break;
-  case cfautorelease: Effect = Effect.withKind(Autorelease); break;
-  case cfmakecollectable: Effect = Effect.withKind(DoNothing); break;
-  }
+  ArgEffect Effect(AE, ObjKind::CF);
 
   ScratchArgs = AF.add(ScratchArgs, 0, Effect);
   return getPersistentSummary(RetEffect::MakeNoRet(),




More information about the cfe-commits mailing list