[clang] cbdc760 - [analyzer] Add a few more safe functions to call. (#81532)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 14 14:45:32 PST 2024
Author: Ryosuke Niwa
Date: 2024-02-14T14:45:29-08:00
New Revision: cbdc7605edca26ff75a28f080089a835ed9dba92
URL: https://github.com/llvm/llvm-project/commit/cbdc7605edca26ff75a28f080089a835ed9dba92
DIFF: https://github.com/llvm/llvm-project/commit/cbdc7605edca26ff75a28f080089a835ed9dba92.diff
LOG: [analyzer] Add a few more safe functions to call. (#81532)
Added checkedDowncast, uncheckedDowncast, & toString as safe functions
to call in alpha.webkit.UncountedCallArgsChecker.
Added:
clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
Removed:
clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 96784d42d09fa4..08ba553d16ed14 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -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;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index c84e1f9c244a88..e2e1add31c9b17 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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;
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
similarity index 55%
rename from clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
rename to clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
index 28156623d9a0fd..a87446564870cd 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
@@ -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());
}
More information about the cfe-commits
mailing list