Skip to content

Commit

Permalink
[analyzer] [RetainCountChecker] Remove redundant enum UnarySummaryKind
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D56072

llvm-svn: 350861
  • Loading branch information
George Karpenkov committed Jan 10, 2019
1 parent 29e1ca8 commit 4cb992e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
Expand Up @@ -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);
Expand Down
24 changes: 8 additions & 16 deletions clang/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
Expand Up @@ -194,7 +194,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
} 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") {
Expand Down Expand Up @@ -307,16 +307,16 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
// 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);
}
Expand All @@ -326,7 +326,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
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);
}
Expand All @@ -350,7 +350,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
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.
Expand Down Expand Up @@ -644,11 +644,9 @@ RetainSummaryManager::canEval(const CallExpr *CE, const FunctionDecl *FD,
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());
Expand All @@ -659,13 +657,7 @@ RetainSummaryManager::getUnarySummary(const FunctionType* FT,
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(),
Expand Down

0 comments on commit 4cb992e

Please sign in to comment.