Skip to content

Commit 5070c1e

Browse files
rniwahaoNoQ
authored andcommitted
[analyzer] WebKit checkers: recognize dynamicDowncast as a safe function.
It can take raw pointers without triggering a warning. Also retire the support for makeRef and makeWeakPtr as they have been removed from WebKit.
1 parent dd473f1 commit 5070c1e

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ bool isPtrConversion(const FunctionDecl *F) {
186186
// FIXME: check # of params == 1
187187
const auto FunctionName = safeGetName(F);
188188
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
189-
FunctionName == "makeWeakPtr"
190-
189+
FunctionName == "dynamicDowncast"
191190
|| FunctionName == "downcast" || FunctionName == "bitwise_cast")
192191
return true;
193192

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class UncountedCallArgsChecker
149149

150150
auto name = safeGetName(Callee);
151151
if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
152-
name == "makeWeakPtr" || name == "downcast" || name == "bitwise_cast" ||
152+
name == "dynamicDowncast" || name == "downcast" || name == "bitwise_cast" ||
153153
name == "is" || name == "equal" || name == "hash" ||
154154
name == "isType"
155155
// FIXME: Most/all of these should be implemented via attributes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
class Base {
5+
public:
6+
inline void ref();
7+
inline void deref();
8+
};
9+
10+
class Derived : public Base {
11+
public:
12+
virtual ~Derived();
13+
14+
void ref() const;
15+
void deref() const;
16+
};
17+
18+
class SubDerived final : public Derived {
19+
};
20+
21+
class OtherObject {
22+
public:
23+
Derived* obj();
24+
};
25+
26+
template<typename Target, typename Source>
27+
inline Target* dynamicDowncast(Source* source)
28+
{
29+
return static_cast<Target*>(source);
30+
}
31+
32+
void foo(OtherObject* other)
33+
{
34+
dynamicDowncast<SubDerived>(other->obj());
35+
}

clang/test/Analysis/Checkers/WebKit/call-args.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,6 @@ namespace param_forwarding_method {
262262
}
263263
}
264264

265-
namespace make_ref {
266-
void makeRef(RefCountable*) {}
267-
void makeRefPtr(RefCountable*) {}
268-
void makeWeakPtr(RefCountable*) {}
269-
void makeWeakPtr(RefCountable&) {}
270-
271-
void foo() {
272-
makeRef(provide());
273-
makeRefPtr(provide());
274-
RefPtr<RefCountable> a(provide());
275-
Ref<RefCountable> b(provide());
276-
makeWeakPtr(provide());
277-
makeWeakPtr(*provide());
278-
}
279-
}
280-
281265
namespace downcast {
282266
void consume_ref_countable(RefCountable*) {}
283267
RefCountable* downcast(RefCountable*) { return nullptr; }

0 commit comments

Comments
 (0)