diff options
author | Jordan Rose <jordan_rose@apple.com> | 2015-03-30 20:17:47 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2015-03-30 20:17:47 +0000 |
commit | 218772f87ef53d1db4f03f4bd131482bdcc1089c (patch) | |
tree | ab25dc6359cd020e03d4a106504cace6ca8410c4 /clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | |
parent | b8afdd604423f852fb1935855d4dd16e03fea987 (diff) | |
download | bcm5719-llvm-218772f87ef53d1db4f03f4bd131482bdcc1089c.tar.gz bcm5719-llvm-218772f87ef53d1db4f03f4bd131482bdcc1089c.zip |
[analyzer] Don't special-case ivars backing +0 properties.
Give up this checking in order to continue tracking that these values came from
direct ivar access, which will be important in the next commit.
Part of rdar://problem/20335433
llvm-svn: 233591
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 83 |
1 files changed, 1 insertions, 82 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 6b8596efb1b..ad4e31db943 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -2821,63 +2821,6 @@ static bool wasLoadedFromIvar(SymbolRef Sym) { return false; } -/// Returns the property that claims this instance variable, if any. -static const ObjCPropertyDecl *findPropForIvar(const ObjCIvarDecl *Ivar) { - auto IsPropertyForIvar = [Ivar](const ObjCPropertyDecl *Prop) -> bool { - return Prop->getPropertyIvarDecl() == Ivar; - }; - - const ObjCInterfaceDecl *Interface = Ivar->getContainingInterface(); - auto PropIter = std::find_if(Interface->prop_begin(), Interface->prop_end(), - IsPropertyForIvar); - if (PropIter != Interface->prop_end()) { - return *PropIter; - } - - for (auto Extension : Interface->visible_extensions()) { - PropIter = std::find_if(Extension->prop_begin(), Extension->prop_end(), - IsPropertyForIvar); - if (PropIter != Extension->prop_end()) - return *PropIter; - } - - return nullptr; -} - -namespace { - enum Retaining_t { - NonRetaining, - Retaining - }; -} - -static Optional<Retaining_t> getRetainSemantics(const ObjCPropertyDecl *Prop) { - assert(Prop->getPropertyIvarDecl() && - "should only be used for properties with synthesized implementations"); - - if (!Prop->hasWrittenStorageAttribute()) { - // Don't assume anything about the retain semantics of readonly properties. - if (Prop->isReadOnly()) - return None; - - // Don't assume anything about readwrite properties with manually-supplied - // setters. - const ObjCMethodDecl *Setter = Prop->getSetterMethodDecl(); - bool HasManualSetter = std::any_of(Setter->redecls_begin(), - Setter->redecls_end(), - [](const Decl *SetterRedecl) -> bool { - return cast<ObjCMethodDecl>(SetterRedecl)->hasBody(); - }); - if (HasManualSetter) - return None; - - // If the setter /is/ synthesized, we're already relying on the retain - // semantics of the property. Continue as normal. - } - - return Prop->isRetaining() ? Retaining : NonRetaining; -} - void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE, CheckerContext &C) const { Optional<Loc> IVarLoc = C.getSVal(IRE).getAs<Loc>(); @@ -2914,14 +2857,6 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE, return; } - // Also don't do anything if the ivar is unretained. If so, we know that - // there's no outstanding retain count for the value. - if (Kind == RetEffect::ObjC) - if (const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl())) - if (auto retainSemantics = getRetainSemantics(Prop)) - if (retainSemantics.getValue() == NonRetaining) - return; - // Note that this value has been loaded from an ivar. C.addTransition(setRefBinding(State, Sym, RV->withIvarAccess())); return; @@ -2935,23 +2870,7 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE, return; } - bool didUpdateState = false; - if (Kind == RetEffect::ObjC) { - // Check if the ivar is known to be unretained. If so, we know that - // there's no outstanding retain count for the value. - if (const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl())) { - if (auto retainSemantics = getRetainSemantics(Prop)) { - if (retainSemantics.getValue() == NonRetaining) { - State = setRefBinding(State, Sym, PlusZero); - didUpdateState = true; - } - } - } - } - - if (!didUpdateState) - State = setRefBinding(State, Sym, PlusZero.withIvarAccess()); - + State = setRefBinding(State, Sym, PlusZero.withIvarAccess()); C.addTransition(State); } |