Skip to content

Commit 7596e70

Browse files
committed
[alpha.webkit.UncountedCallArgsChecker] Add a few more safe functions to call.
Added checkedDowncast, uncheckedDowncast, & toString as safe functions to call.
1 parent 535da10 commit 7596e70

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ bool isPtrConversion(const FunctionDecl *F) {
192192
// FIXME: check # of params == 1
193193
const auto FunctionName = safeGetName(F);
194194
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
195-
FunctionName == "dynamicDowncast"
196-
|| FunctionName == "downcast" || FunctionName == "bitwise_cast")
195+
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
196+
FunctionName == "checkedDowncast" ||
197+
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast"s
197198
return true;
198199

199200
return false;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ class UncountedCallArgsChecker
148148

149149
auto name = safeGetName(Callee);
150150
if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
151-
name == "dynamicDowncast" || name == "downcast" || name == "bitwise_cast" ||
152-
name == "is" || name == "equal" || name == "hash" ||
153-
name == "isType"
151+
name == "dynamicDowncast" || name == "downcast" ||
152+
name == "checkedDowncast" || name == "uncheckedDowncast" ||
153+
name == "bitwise_cast" || name == "is" || name == "equal" ||
154+
name == "hash" || name == "isType" ||
154155
// FIXME: Most/all of these should be implemented via attributes.
155-
|| name == "equalIgnoringASCIICase" ||
156+
name == "equalIgnoringASCIICase" ||
156157
name == "equalIgnoringASCIICaseCommon" ||
157-
name == "equalIgnoringNullity")
158+
name == "equalIgnoringNullity" || name == "toString")
158159
return true;
159160

160161
return false;

clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp renamed to clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,34 @@ class OtherObject {
2323
Derived* obj();
2424
};
2525

26+
class String {
27+
};
28+
2629
template<typename Target, typename Source>
2730
inline Target* dynamicDowncast(Source* source)
2831
{
2932
return static_cast<Target*>(source);
3033
}
3134

35+
template<typename Target, typename Source>
36+
inline Target* checkedDowncast(Source* source)
37+
{
38+
return static_cast<Target*>(source);
39+
}
40+
41+
template<typename Target, typename Source>
42+
inline Target* uncheckedDowncast(Source* source)
43+
{
44+
return static_cast<Target*>(source);
45+
}
46+
47+
template<typename... Types>
48+
String toString(const Types&... values);
49+
3250
void foo(OtherObject* other)
3351
{
3452
dynamicDowncast<SubDerived>(other->obj());
53+
checkedDowncast<SubDerived>(other->obj());
54+
uncheckedDowncast<SubDerived>(other->obj());
55+
toString(other->obj());
3556
}

0 commit comments

Comments
 (0)