File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,16 @@ bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
143143 return false ;
144144}
145145
146+ std::optional<bool > isUncounted (const QualType T) {
147+ if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
148+ if (auto *Decl = Subst->getAssociatedDecl ()) {
149+ if (isRefType (safeGetName (Decl)))
150+ return false ;
151+ }
152+ }
153+ return isUncounted (T->getAsCXXRecordDecl ());
154+ }
155+
146156std::optional<bool > isUncounted (const CXXRecordDecl* Class)
147157{
148158 // Keep isRefCounted first as it's cheaper.
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class CXXMethodDecl;
2020class CXXRecordDecl ;
2121class Decl ;
2222class FunctionDecl ;
23+ class QualType ;
2324class Stmt ;
2425class Type ;
2526
@@ -42,6 +43,10 @@ std::optional<bool> isRefCountable(const clang::CXXRecordDecl* Class);
4243// / \returns true if \p Class is ref-counted, false if not.
4344bool isRefCounted (const clang::CXXRecordDecl *Class);
4445
46+ // / \returns true if \p Class is ref-countable AND not ref-counted, false if
47+ // / not, std::nullopt if inconclusive.
48+ std::optional<bool > isUncounted (const clang::QualType T);
49+
4550// / \returns true if \p Class is ref-countable AND not ref-counted, false if
4651// / not, std::nullopt if inconclusive.
4752std::optional<bool > isUncounted (const clang::CXXRecordDecl* Class);
Original file line number Diff line number Diff line change @@ -87,8 +87,7 @@ class UncountedCallArgsChecker
8787 }
8888 auto *E = MemberCallExpr->getImplicitObjectArgument ();
8989 QualType ArgType = MemberCallExpr->getObjectType ();
90- std::optional<bool > IsUncounted =
91- isUncounted (ArgType->getAsCXXRecordDecl ());
90+ std::optional<bool > IsUncounted = isUncounted (ArgType);
9291 if (IsUncounted && *IsUncounted && !isPtrOriginSafe (E))
9392 reportBugOnThis (E);
9493 }
Original file line number Diff line number Diff line change 1+ // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+ // expected-no-diagnostics
3+
4+ #import " mock-types.h"
5+ #import " mock-system-header.h"
6+ #import " ../../Inputs/system-header-simulator-for-objc-dealloc.h"
7+
8+ @interface Foo : NSObject
9+
10+ @property (nonatomic , readonly ) RefPtr<RefCountable> countable;
11+
12+ - (void )execute ;
13+ - (RefPtr<RefCountable>)_protectedRefCountable ;
14+ @end
15+
16+ @implementation Foo
17+
18+ - (void )execute {
19+ self._protectedRefCountable ->method ();
20+ }
21+
22+ - (RefPtr<RefCountable>)_protectedRefCountable {
23+ return _countable;
24+ }
25+
26+ @end
You can’t perform that action at this time.
0 commit comments