]> granicus.if.org Git - clang/commitdiff
[analyzer] [NFC] Reduce redundancy in RetainSummaryManager by using a function
authorGeorge Karpenkov <ekarpenkov@apple.com>
Thu, 10 Jan 2019 18:15:30 +0000 (18:15 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Thu, 10 Jan 2019 18:15:30 +0000 (18:15 +0000)
Differential Revision: https://reviews.llvm.org/D56282

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350865 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
lib/StaticAnalyzer/Core/RetainSummaryManager.cpp

index 04e5d6a0ba6a5f95b9df2318411368e8d06e9114..62b8fa6cf8ab31054999df29f231711cbfd50915 100644 (file)
@@ -641,10 +641,9 @@ class RetainSummaryManager {
   /// Apply the annotation of {@code pd} in function {@code FD}
   /// to the resulting summary stored in out-parameter {@code Template}.
   /// \return whether an annotation was applied.
-  bool applyFunctionParamAnnotationEffect(const ParmVarDecl *pd,
-                                        unsigned parm_idx,
-                                        const FunctionDecl *FD,
-                                        RetainSummaryTemplate &Template);
+  bool applyParamAnnotationEffect(const ParmVarDecl *pd, unsigned parm_idx,
+                                  const NamedDecl *FD,
+                                  RetainSummaryTemplate &Template);
 
 public:
   RetainSummaryManager(ASTContext &ctx,
index d50601f524a77bc7a54bc0f5a3a15af994862ecd..bc43b8f897eed1ddd6a099ba295fe04c10da7d6a 100644 (file)
@@ -811,8 +811,8 @@ RetainSummaryManager::getRetEffectFromAnnotations(QualType RetTy,
   return None;
 }
 
-bool RetainSummaryManager::applyFunctionParamAnnotationEffect(
-    const ParmVarDecl *pd, unsigned parm_idx, const FunctionDecl *FD,
+bool RetainSummaryManager::applyParamAnnotationEffect(
+    const ParmVarDecl *pd, unsigned parm_idx, const NamedDecl *FD,
     RetainSummaryTemplate &Template) {
   QualType QT = pd->getType();
   if (auto K =
@@ -832,7 +832,7 @@ bool RetainSummaryManager::applyFunctionParamAnnotationEffect(
     if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
       for (const auto *OD : MD->overridden_methods()) {
         const ParmVarDecl *OP = OD->parameters()[parm_idx];
-        if (applyFunctionParamAnnotationEffect(OP, parm_idx, OD, Template))
+        if (applyParamAnnotationEffect(OP, parm_idx, OD, Template))
           return true;
       }
     }
@@ -853,10 +853,8 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ,
   // Effects on the parameters.
   unsigned parm_idx = 0;
   for (auto pi = FD->param_begin(),
-         pe = FD->param_end(); pi != pe; ++pi, ++parm_idx) {
-    const ParmVarDecl *pd = *pi;
-    applyFunctionParamAnnotationEffect(pd, parm_idx, FD, Template);
-  }
+         pe = FD->param_end(); pi != pe; ++pi, ++parm_idx)
+    applyParamAnnotationEffect(*pi, parm_idx, FD, Template);
 
   QualType RetTy = FD->getReturnType();
   if (Optional<RetEffect> RetE = getRetEffectFromAnnotations(RetTy, FD))
@@ -882,19 +880,9 @@ RetainSummaryManager::updateSummaryFromAnnotations(const RetainSummary *&Summ,
   // Effects on the parameters.
   unsigned parm_idx = 0;
   for (auto pi = MD->param_begin(), pe = MD->param_end(); pi != pe;
-       ++pi, ++parm_idx) {
-    const ParmVarDecl *pd = *pi;
-    QualType QT = pd->getType();
-    if (auto K =
-            hasAnyEnabledAttrOf<NSConsumedAttr, CFConsumedAttr, OSConsumedAttr>(
-                pd, QT)) {
-      Template->addArg(AF, parm_idx, ArgEffect(DecRef, *K));
-    } else if (auto K = hasAnyEnabledAttrOf<CFReturnsRetainedAttr>(pd, QT)) {
-      Template->addArg(AF, parm_idx, ArgEffect(RetainedOutParameter, *K));
-    } else if (auto K = hasAnyEnabledAttrOf<CFReturnsNotRetainedAttr>(pd, QT)) {
-      Template->addArg(AF, parm_idx, ArgEffect(UnretainedOutParameter, *K));
-    }
-  }
+       ++pi, ++parm_idx)
+    applyParamAnnotationEffect(*pi, parm_idx, MD, Template);
+
   QualType RetTy = MD->getReturnType();
   if (Optional<RetEffect> RetE = getRetEffectFromAnnotations(RetTy, MD))
     Template->setRetEffect(*RetE);