Skip to content

Commit cbdc760

Browse files
authored
[analyzer] Add a few more safe functions to call. (#81532)
Added checkedDowncast, uncheckedDowncast, & toString as safe functions to call in alpha.webkit.UncountedCallArgsChecker.
1 parent 3a49dfb commit cbdc760

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
@@ -194,8 +194,9 @@ bool isPtrConversion(const FunctionDecl *F) {
194194
// FIXME: check # of params == 1
195195
const auto FunctionName = safeGetName(F);
196196
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
197-
FunctionName == "dynamicDowncast"
198-
|| FunctionName == "downcast" || FunctionName == "bitwise_cast")
197+
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
198+
FunctionName == "checkedDowncast" ||
199+
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast")
199200
return true;
200201

201202
return false;

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

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

175175
auto name = safeGetName(Callee);
176176
if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
177-
name == "dynamicDowncast" || name == "downcast" || name == "bitwise_cast" ||
178-
name == "is" || name == "equal" || name == "hash" ||
179-
name == "isType"
177+
name == "dynamicDowncast" || name == "downcast" ||
178+
name == "checkedDowncast" || name == "uncheckedDowncast" ||
179+
name == "bitwise_cast" || name == "is" || name == "equal" ||
180+
name == "hash" || name == "isType" ||
180181
// FIXME: Most/all of these should be implemented via attributes.
181-
|| name == "equalIgnoringASCIICase" ||
182+
name == "equalIgnoringASCIICase" ||
182183
name == "equalIgnoringASCIICaseCommon" ||
183-
name == "equalIgnoringNullity")
184+
name == "equalIgnoringNullity" || name == "toString")
184185
return true;
185186

186187
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)