Skip to content

Commit

Permalink
[analyzer] Add a few more safe functions to call. (#81532)
Browse files Browse the repository at this point in the history
Added checkedDowncast, uncheckedDowncast, & toString as safe functions
to call in alpha.webkit.UncountedCallArgsChecker.
  • Loading branch information
rniwa committed Feb 14, 2024
1 parent 3a49dfb commit cbdc760
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ bool isPtrConversion(const FunctionDecl *F) {
// FIXME: check # of params == 1
const auto FunctionName = safeGetName(F);
if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
FunctionName == "dynamicDowncast"
|| FunctionName == "downcast" || FunctionName == "bitwise_cast")
FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
FunctionName == "checkedDowncast" ||
FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast")
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ class UncountedCallArgsChecker

auto name = safeGetName(Callee);
if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
name == "dynamicDowncast" || name == "downcast" || name == "bitwise_cast" ||
name == "is" || name == "equal" || name == "hash" ||
name == "isType"
name == "dynamicDowncast" || name == "downcast" ||
name == "checkedDowncast" || name == "uncheckedDowncast" ||
name == "bitwise_cast" || name == "is" || name == "equal" ||
name == "hash" || name == "isType" ||
// FIXME: Most/all of these should be implemented via attributes.
|| name == "equalIgnoringASCIICase" ||
name == "equalIgnoringASCIICase" ||
name == "equalIgnoringASCIICaseCommon" ||
name == "equalIgnoringNullity")
name == "equalIgnoringNullity" || name == "toString")
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,34 @@ class OtherObject {
Derived* obj();
};

class String {
};

template<typename Target, typename Source>
inline Target* dynamicDowncast(Source* source)
{
return static_cast<Target*>(source);
}

template<typename Target, typename Source>
inline Target* checkedDowncast(Source* source)
{
return static_cast<Target*>(source);
}

template<typename Target, typename Source>
inline Target* uncheckedDowncast(Source* source)
{
return static_cast<Target*>(source);
}

template<typename... Types>
String toString(const Types&... values);

void foo(OtherObject* other)
{
dynamicDowncast<SubDerived>(other->obj());
checkedDowncast<SubDerived>(other->obj());
uncheckedDowncast<SubDerived>(other->obj());
toString(other->obj());
}

0 comments on commit cbdc760

Please sign in to comment.