summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2019-01-10 18:13:46 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2019-01-10 18:13:46 +0000
commit6c6bd3ce01117d7c975f2d847e71764f7cf96f75 (patch)
tree451133bfa817c5dfb632f88aeb233f4451fc49c2
parent1581cdda759fb5b516ff2de1eb2aabf38fe7a7a4 (diff)
[analyzer] [NFC] Move ObjKind into a separate top-level enum in RetainSummaryManager.
Allows using it in future outside of RetEffect. Differential Revision: https://reviews.llvm.org/D56039 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350857 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/StaticAnalyzer/Core/RetainSummaryManager.h43
-rw-r--r--lib/ARCMigrate/ObjCMT.cpp14
-rw-r--r--lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp20
-rw-r--r--lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h12
-rw-r--r--lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp8
-rw-r--r--lib/StaticAnalyzer/Core/RetainSummaryManager.cpp42
6 files changed, 70 insertions, 69 deletions
diff --git a/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h b/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
index 9540f01c70..98aad57517 100644
--- a/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
+++ b/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
@@ -36,6 +36,22 @@ using namespace ento;
namespace clang {
namespace ento {
+/// Determines the object kind of a tracked object.
+enum class ObjKind {
+ /// Indicates that the tracked object is a CF object. This is
+ /// important between GC and non-GC code.
+ CF,
+ /// Indicates that the tracked object is an Objective-C object.
+ ObjC,
+ /// Indicates that the tracked object could be a CF or Objective-C object.
+ AnyObj,
+ /// Indicates that the tracked object is a generalized object.
+ Generalized,
+
+ /// A descendant of OSObject.
+ OS
+};
+
/// An ArgEffect summarizes the retain count behavior on an argument or receiver
/// to a function or method.
enum ArgEffect {
@@ -144,27 +160,12 @@ public:
NoRetHard
};
- /// Determines the object kind of a tracked object.
- enum ObjKind {
- /// Indicates that the tracked object is a CF object. This is
- /// important between GC and non-GC code.
- CF,
- /// Indicates that the tracked object is an Objective-C object.
- ObjC,
- /// Indicates that the tracked object could be a CF or Objective-C object.
- AnyObj,
- /// Indicates that the tracked object is a generalized object.
- Generalized,
-
- /// A descendant of OSObject.
- OS
- };
private:
Kind K;
ObjKind O;
- RetEffect(Kind k, ObjKind o = AnyObj) : K(k), O(o) {}
+ RetEffect(Kind k, ObjKind o = ObjKind::AnyObj) : K(k), O(o) {}
public:
Kind getKind() const { return K; }
@@ -184,7 +185,7 @@ public:
}
static RetEffect MakeOwnedWhenTrackedReceiver() {
- return RetEffect(OwnedWhenTrackedReceiver, ObjC);
+ return RetEffect(OwnedWhenTrackedReceiver, ObjKind::ObjC);
}
static RetEffect MakeOwned(ObjKind o) {
@@ -194,7 +195,7 @@ public:
return RetEffect(NotOwnedSymbol, o);
}
static RetEffect MakeGCNotOwned() {
- return RetEffect(GCNotOwnedSymbol, ObjC);
+ return RetEffect(GCNotOwnedSymbol, ObjKind::ObjC);
}
static RetEffect MakeNoRet() {
return RetEffect(NoRet);
@@ -659,9 +660,9 @@ public:
TrackObjCAndCFObjects(trackObjCAndCFObjects),
TrackOSObjects(trackOSObjects),
AF(BPAlloc),
- ObjCAllocRetE(usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
- : RetEffect::MakeOwned(RetEffect::ObjC)),
- ObjCInitRetE(usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
+ ObjCAllocRetE(usesARC ? RetEffect::MakeNotOwned(ObjKind::ObjC)
+ : RetEffect::MakeOwned(ObjKind::ObjC)),
+ ObjCInitRetE(usesARC ? RetEffect::MakeNotOwned(ObjKind::ObjC)
: RetEffect::MakeOwnedWhenTrackedReceiver()) {
InitializeClassMethodSummaries();
InitializeMethodSummaries();
diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp
index d202411429..b349434907 100644
--- a/lib/ARCMigrate/ObjCMT.cpp
+++ b/lib/ARCMigrate/ObjCMT.cpp
@@ -1460,14 +1460,14 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
if (!ResultAnnotated) {
RetEffect Ret = CE.getReturnValue();
const char *AnnotationString = nullptr;
- if (Ret.getObjKind() == RetEffect::CF) {
+ if (Ret.getObjKind() == ObjKind::CF) {
if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
AnnotationString = " CF_RETURNS_RETAINED";
else if (Ret.notOwned() &&
NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
AnnotationString = " CF_RETURNS_NOT_RETAINED";
}
- else if (Ret.getObjKind() == RetEffect::ObjC) {
+ else if (Ret.getObjKind() == ObjKind::ObjC) {
if (Ret.isOwned() && NSAPIObj->isMacroDefined("NS_RETURNS_RETAINED"))
AnnotationString = " NS_RETURNS_RETAINED";
}
@@ -1520,7 +1520,7 @@ ObjCMigrateASTConsumer::CF_BRIDGING_KIND
bool ReturnCFAudited = false;
if (!FuncIsReturnAnnotated) {
RetEffect Ret = CE.getReturnValue();
- if (Ret.getObjKind() == RetEffect::CF &&
+ if (Ret.getObjKind() == ObjKind::CF &&
(Ret.isOwned() || Ret.notOwned()))
ReturnCFAudited = true;
else if (!AuditedType(FuncDecl->getReturnType()))
@@ -1574,14 +1574,14 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx,
if (!ResultAnnotated) {
RetEffect Ret = CE.getReturnValue();
const char *AnnotationString = nullptr;
- if (Ret.getObjKind() == RetEffect::CF) {
+ if (Ret.getObjKind() == ObjKind::CF) {
if (Ret.isOwned() && NSAPIObj->isMacroDefined("CF_RETURNS_RETAINED"))
AnnotationString = " CF_RETURNS_RETAINED";
else if (Ret.notOwned() &&
NSAPIObj->isMacroDefined("CF_RETURNS_NOT_RETAINED"))
AnnotationString = " CF_RETURNS_NOT_RETAINED";
}
- else if (Ret.getObjKind() == RetEffect::ObjC) {
+ else if (Ret.getObjKind() == ObjKind::ObjC) {
ObjCMethodFamily OMF = MethodDecl->getMethodFamily();
switch (OMF) {
case clang::OMF_alloc:
@@ -1649,8 +1649,8 @@ void ObjCMigrateASTConsumer::migrateAddMethodAnnotation(
if (!MethodIsReturnAnnotated) {
RetEffect Ret = CE.getReturnValue();
- if ((Ret.getObjKind() == RetEffect::CF ||
- Ret.getObjKind() == RetEffect::ObjC) &&
+ if ((Ret.getObjKind() == ObjKind::CF ||
+ Ret.getObjKind() == ObjKind::ObjC) &&
(Ret.isOwned() || Ret.notOwned())) {
AddCFAnnotations(Ctx, CE, MethodDecl, false);
return;
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
index 87c1ad9edb..a9b6d6839d 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -299,12 +299,12 @@ void RetainCountChecker::processObjCLiterals(CheckerContext &C,
}
// Return the object as autoreleased.
- // RetEffect RE = RetEffect::MakeNotOwned(RetEffect::ObjC);
+ // RetEffect RE = RetEffect::MakeNotOwned(ObjKind::ObjC);
if (SymbolRef sym =
state->getSVal(Ex, pred->getLocationContext()).getAsSymbol()) {
QualType ResultTy = Ex->getType();
state = setRefBinding(state, sym,
- RefVal::makeNotOwned(RetEffect::ObjC, ResultTy));
+ RefVal::makeNotOwned(ObjKind::ObjC, ResultTy));
}
C.addTransition(state);
@@ -330,7 +330,7 @@ void RetainCountChecker::checkPostStmt(const ObjCBoxedExpr *Ex,
if (SymbolRef Sym = Pred->getSVal(Ex).getAsSymbol()) {
QualType ResultTy = Ex->getType();
State = setRefBinding(State, Sym,
- RefVal::makeNotOwned(RetEffect::ObjC, ResultTy));
+ RefVal::makeNotOwned(ObjKind::ObjC, ResultTy));
}
C.addTransition(State);
@@ -351,11 +351,11 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE,
// forgiving about what the surrounding code is allowed to do.
QualType Ty = Sym->getType();
- RetEffect::ObjKind Kind;
+ ObjKind Kind;
if (Ty->isObjCRetainableType())
- Kind = RetEffect::ObjC;
+ Kind = ObjKind::ObjC;
else if (coreFoundation::isCFObjectRef(Ty))
- Kind = RetEffect::CF;
+ Kind = ObjKind::CF;
else
return;
@@ -514,7 +514,7 @@ static bool isPointerToObject(QualType QT) {
/// OSObjects are escaped when passed to void * / etc.
static bool shouldEscapeArgumentOnCall(const CallEvent &CE, unsigned ArgIdx,
const RefVal *TrackedValue) {
- if (TrackedValue->getObjKind() != RetEffect::OS)
+ if (TrackedValue->getObjKind() != ObjKind::OS)
return false;
if (ArgIdx >= CE.parameters().size())
return false;
@@ -583,7 +583,7 @@ static ProgramStateRef updateOutParameter(ProgramStateRef State,
switch (Effect) {
case UnretainedOutParameter:
State = setRefBinding(State, Pointee,
- RefVal::makeNotOwned(RetEffect::CF, PointeeTy));
+ RefVal::makeNotOwned(ObjKind::CF, PointeeTy));
break;
case RetainedOutParameter:
// Do nothing. Retained out parameters will either point to a +1 reference
@@ -1407,11 +1407,11 @@ void RetainCountChecker::checkBeginFunction(CheckerContext &Ctx) const {
const ArgEffect *AE = CalleeSideArgEffects.lookup(idx);
if (AE && *AE == DecRef && isISLObjectRef(Ty)) {
state = setRefBinding(
- state, Sym, RefVal::makeOwned(RetEffect::ObjKind::Generalized, Ty));
+ state, Sym, RefVal::makeOwned(ObjKind::Generalized, Ty));
} else if (isISLObjectRef(Ty)) {
state = setRefBinding(
state, Sym,
- RefVal::makeNotOwned(RetEffect::ObjKind::Generalized, Ty));
+ RefVal::makeNotOwned(ObjKind::Generalized, Ty));
}
}
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
index 151aa49ed4..d8bbe6fcdd 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
@@ -94,7 +94,7 @@ private:
/// The kind of object being tracked (CF or ObjC or OSObject), if known.
///
- /// See the RetEffect::ObjKind enum for possible values.
+ /// See the ObjKind enum for possible values.
unsigned RawObjectKind : 3;
/// True if the current state and/or retain count may turn out to not be the
@@ -108,7 +108,7 @@ private:
/// them.
unsigned RawIvarAccessHistory : 2;
- RefVal(Kind k, RetEffect::ObjKind o, unsigned cnt, unsigned acnt, QualType t,
+ RefVal(Kind k, ObjKind o, unsigned cnt, unsigned acnt, QualType t,
IvarAccessHistory IvarAccess)
: Cnt(cnt), ACnt(acnt), T(t), RawKind(static_cast<unsigned>(k)),
RawObjectKind(static_cast<unsigned>(o)),
@@ -121,8 +121,8 @@ private:
public:
Kind getKind() const { return static_cast<Kind>(RawKind); }
- RetEffect::ObjKind getObjKind() const {
- return static_cast<RetEffect::ObjKind>(RawObjectKind);
+ ObjKind getObjKind() const {
+ return static_cast<ObjKind>(RawObjectKind);
}
unsigned getCount() const { return Cnt; }
@@ -170,7 +170,7 @@ public:
/// current function, at least partially.
///
/// Most commonly, this is an owned object with a retain count of +1.
- static RefVal makeOwned(RetEffect::ObjKind o, QualType t) {
+ static RefVal makeOwned(ObjKind o, QualType t) {
return RefVal(Owned, o, /*Count=*/1, 0, t, IvarAccessHistory::None);
}
@@ -178,7 +178,7 @@ public:
/// the current function.
///
/// Most commonly, this is an unowned object with a retain count of +0.
- static RefVal makeNotOwned(RetEffect::ObjKind o, QualType t) {
+ static RefVal makeNotOwned(ObjKind o, QualType t) {
return RefVal(NotOwned, o, /*Count=*/0, 0, t, IvarAccessHistory::None);
}
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 74dd1e149e..44cb7553c0 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -156,17 +156,17 @@ static void generateDiagnosticsForCallLike(ProgramStateRef CurrSt,
}
}
- if (CurrV.getObjKind() == RetEffect::CF) {
+ if (CurrV.getObjKind() == ObjKind::CF) {
os << " returns a Core Foundation object of type "
<< Sym->getType().getAsString() << " with a ";
- } else if (CurrV.getObjKind() == RetEffect::OS) {
+ } else if (CurrV.getObjKind() == ObjKind::OS) {
os << " returns an OSObject of type " << getPrettyTypeName(Sym->getType())
<< " with a ";
- } else if (CurrV.getObjKind() == RetEffect::Generalized) {
+ } else if (CurrV.getObjKind() == ObjKind::Generalized) {
os << " returns an object of type " << Sym->getType().getAsString()
<< " with a ";
} else {
- assert(CurrV.getObjKind() == RetEffect::ObjC);
+ assert(CurrV.getObjKind() == ObjKind::ObjC);
QualType T = Sym->getType();
if (!isa<ObjCObjectPointerType>(T)) {
os << " returns an Objective-C object with a ";
diff --git a/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp b/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
index 13955b5e50..465449b150 100644
--- a/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
+++ b/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
@@ -199,7 +199,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
} else if (FName == "CMBufferQueueDequeueAndRetain" ||
FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
// Part of: <rdar://problem/39390714>.
- return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
+ return getPersistentSummary(RetEffect::MakeOwned(ObjKind::CF),
ScratchArgs,
DoNothing,
DoNothing);
@@ -213,7 +213,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
FName == "IOOpenFirmwarePathMatching"))) {
// Part of <rdar://problem/6961230>. (IOKit)
// This should be addressed using a API table.
- return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
+ return getPersistentSummary(RetEffect::MakeOwned(ObjKind::CF),
ScratchArgs, DoNothing, DoNothing);
} else if (FName == "IOServiceGetMatchingService" ||
FName == "IOServiceGetMatchingServices") {
@@ -249,7 +249,7 @@ const RetainSummary *RetainSummaryManager::getSummaryForObjCOrCFObject(
// passed to CGBitmapContextCreateWithData is released via
// a callback and doing full IPA to make sure this is done correctly.
ScratchArgs = AF.add(ScratchArgs, 8, StopTracking);
- return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
+ return getPersistentSummary(RetEffect::MakeOwned(ObjKind::CF),
ScratchArgs, DoNothing, DoNothing);
} else if (FName == "CVPixelBufferCreateWithPlanarBytes") {
// FIXES: <rdar://problem/7283567>
@@ -702,25 +702,25 @@ RetainSummaryManager::getOSSummaryFreeRule(const FunctionDecl *FD) {
const RetainSummary *
RetainSummaryManager::getOSSummaryCreateRule(const FunctionDecl *FD) {
- return getPersistentSummary(RetEffect::MakeOwned(RetEffect::OS),
+ return getPersistentSummary(RetEffect::MakeOwned(ObjKind::OS),
AF.getEmptyMap());
}
const RetainSummary *
RetainSummaryManager::getOSSummaryGetRule(const FunctionDecl *FD) {
- return getPersistentSummary(RetEffect::MakeNotOwned(RetEffect::OS),
+ return getPersistentSummary(RetEffect::MakeNotOwned(ObjKind::OS),
AF.getEmptyMap());
}
const RetainSummary *
RetainSummaryManager::getCFSummaryCreateRule(const FunctionDecl *FD) {
- return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
+ return getPersistentSummary(RetEffect::MakeOwned(ObjKind::CF),
ArgEffects(AF.getEmptyMap()));
}
const RetainSummary *
RetainSummaryManager::getCFSummaryGetRule(const FunctionDecl *FD) {
- return getPersistentSummary(RetEffect::MakeNotOwned(RetEffect::CF),
+ return getPersistentSummary(RetEffect::MakeNotOwned(ObjKind::CF),
ArgEffects(AF.getEmptyMap()),
DoNothing, DoNothing);
}
@@ -741,26 +741,26 @@ RetainSummaryManager::getRetEffectFromAnnotations(QualType RetTy,
if (D->hasAttr<NSReturnsNotRetainedAttr>() ||
D->hasAttr<NSReturnsAutoreleasedAttr>())
- return RetEffect::MakeNotOwned(RetEffect::ObjC);
+ return RetEffect::MakeNotOwned(ObjKind::ObjC);
} else if (!RetTy->isPointerType()) {
return None;
}
if (hasEnabledAttr<CFReturnsRetainedAttr>(D)) {
- return RetEffect::MakeOwned(RetEffect::CF);
+ return RetEffect::MakeOwned(ObjKind::CF);
} else if (hasEnabledAttr<OSReturnsRetainedAttr>(D)) {
- return RetEffect::MakeOwned(RetEffect::OS);
+ return RetEffect::MakeOwned(ObjKind::OS);
} else if (hasRCAnnotation(D, "rc_ownership_returns_retained")) {
- return RetEffect::MakeOwned(RetEffect::Generalized);
+ return RetEffect::MakeOwned(ObjKind::Generalized);
}
if (hasEnabledAttr<CFReturnsNotRetainedAttr>(D)) {
- return RetEffect::MakeNotOwned(RetEffect::CF);
+ return RetEffect::MakeNotOwned(ObjKind::CF);
} else if (hasEnabledAttr<OSReturnsNotRetainedAttr>(D)) {
- return RetEffect::MakeNotOwned(RetEffect::OS);
+ return RetEffect::MakeNotOwned(ObjKind::OS);
} else if (hasRCAnnotation(D, "rc_ownership_returns_not_retained")) {
- return RetEffect::MakeNotOwned(RetEffect::Generalized);
+ return RetEffect::MakeNotOwned(ObjKind::Generalized);
}
if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
@@ -893,7 +893,7 @@ RetainSummaryManager::getStandardMethodSummary(const ObjCMethodDecl *MD,
// FIXME: Does the non-threaded performSelector family really belong here?
// The selector could be, say, @selector(copy).
if (cocoa::isCocoaObjectRef(RetTy))
- ResultEff = RetEffect::MakeNotOwned(RetEffect::ObjC);
+ ResultEff = RetEffect::MakeNotOwned(ObjKind::ObjC);
else if (coreFoundation::isCFObjectRef(RetTy)) {
// ObjCMethodDecl currently doesn't consider CF objects as valid return
// values for alloc, new, copy, or mutableCopy, so we have to
@@ -905,14 +905,14 @@ RetainSummaryManager::getStandardMethodSummary(const ObjCMethodDecl *MD,
case OMF_new:
case OMF_copy:
case OMF_mutableCopy:
- ResultEff = RetEffect::MakeOwned(RetEffect::CF);
+ ResultEff = RetEffect::MakeOwned(ObjKind::CF);
break;
default:
- ResultEff = RetEffect::MakeNotOwned(RetEffect::CF);
+ ResultEff = RetEffect::MakeNotOwned(ObjKind::CF);
break;
}
} else {
- ResultEff = RetEffect::MakeNotOwned(RetEffect::CF);
+ ResultEff = RetEffect::MakeNotOwned(ObjKind::CF);
}
}
break;
@@ -927,7 +927,7 @@ RetainSummaryManager::getStandardMethodSummary(const ObjCMethodDecl *MD,
if (cocoa::isCocoaObjectRef(RetTy))
ResultEff = ObjCAllocRetE;
else if (coreFoundation::isCFObjectRef(RetTy))
- ResultEff = RetEffect::MakeOwned(RetEffect::CF);
+ ResultEff = RetEffect::MakeOwned(ObjKind::CF);
break;
case OMF_autorelease:
ReceiverEff = Autorelease;
@@ -1033,7 +1033,7 @@ void RetainSummaryManager::InitializeClassMethodSummaries() {
// Create the [NSAssertionHandler currentHander] summary.
addClassMethSummary("NSAssertionHandler", "currentHandler",
- getPersistentSummary(RetEffect::MakeNotOwned(RetEffect::ObjC),
+ getPersistentSummary(RetEffect::MakeNotOwned(ObjKind::ObjC),
ScratchArgs));
// Create the [NSAutoreleasePool addObject:] summary.
@@ -1063,7 +1063,7 @@ void RetainSummaryManager::InitializeMethodSummaries() {
const RetainSummary *AllocSumm = getPersistentSummary(ObjCAllocRetE,
ScratchArgs);
const RetainSummary *CFAllocSumm =
- getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), ScratchArgs);
+ getPersistentSummary(RetEffect::MakeOwned(ObjKind::CF), ScratchArgs);
// Create the "retain" selector.
RetEffect NoRet = RetEffect::MakeNoRet();