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) {
143
143
return false ;
144
144
}
145
145
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
+
146
156
std::optional<bool > isUncounted (const CXXRecordDecl* Class)
147
157
{
148
158
// Keep isRefCounted first as it's cheaper.
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class CXXMethodDecl;
20
20
class CXXRecordDecl ;
21
21
class Decl ;
22
22
class FunctionDecl ;
23
+ class QualType ;
23
24
class Stmt ;
24
25
class Type ;
25
26
@@ -42,6 +43,10 @@ std::optional<bool> isRefCountable(const clang::CXXRecordDecl* Class);
42
43
// / \returns true if \p Class is ref-counted, false if not.
43
44
bool isRefCounted (const clang::CXXRecordDecl *Class);
44
45
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
+
45
50
// / \returns true if \p Class is ref-countable AND not ref-counted, false if
46
51
// / not, std::nullopt if inconclusive.
47
52
std::optional<bool > isUncounted (const clang::CXXRecordDecl* Class);
Original file line number Diff line number Diff line change @@ -87,8 +87,7 @@ class UncountedCallArgsChecker
87
87
}
88
88
auto *E = MemberCallExpr->getImplicitObjectArgument ();
89
89
QualType ArgType = MemberCallExpr->getObjectType ();
90
- std::optional<bool > IsUncounted =
91
- isUncounted (ArgType->getAsCXXRecordDecl ());
90
+ std::optional<bool > IsUncounted = isUncounted (ArgType);
92
91
if (IsUncounted && *IsUncounted && !isPtrOriginSafe (E))
93
92
reportBugOnThis (E);
94
93
}
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