Author: Ryosuke Niwa Date: 2023-10-19T16:10:57-07:00 New Revision: 5070c1e3b07c5b384fe0a064aa99f25b8af4b7e9
URL: https://github.com/llvm/llvm-project/commit/5070c1e3b07c5b384fe0a064aa99f25b8af4b7e9 DIFF: https://github.com/llvm/llvm-project/commit/5070c1e3b07c5b384fe0a064aa99f25b8af4b7e9.diff LOG: [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. Added: clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp clang/test/Analysis/Checkers/WebKit/call-args.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 9b1d7ae3e6a320c..c1f180f31338cb3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -186,8 +186,7 @@ bool isPtrConversion(const FunctionDecl *F) { // FIXME: check # of params == 1 const auto FunctionName = safeGetName(F); if (FunctionName == "getPtr" || FunctionName == "WeakPtr" || - FunctionName == "makeWeakPtr" - + FunctionName == "dynamicDowncast" || FunctionName == "downcast" || FunctionName == "bitwise_cast") return true; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 4ae8c442fa70755..407b6ba7a76428c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -149,7 +149,7 @@ class UncountedCallArgsChecker auto name = safeGetName(Callee); if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" || - name == "makeWeakPtr" || name == "downcast" || name == "bitwise_cast" || + name == "dynamicDowncast" || name == "downcast" || name == "bitwise_cast" || name == "is" || name == "equal" || name == "hash" || name == "isType" // FIXME: Most/all of these should be implemented via attributes. diff --git a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp b/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp new file mode 100644 index 000000000000000..28156623d9a0fd7 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s +// expected-no-diagnostics + +class Base { +public: + inline void ref(); + inline void deref(); +}; + +class Derived : public Base { +public: + virtual ~Derived(); + + void ref() const; + void deref() const; +}; + +class SubDerived final : public Derived { +}; + +class OtherObject { +public: + Derived* obj(); +}; + +template<typename Target, typename Source> +inline Target* dynamicDowncast(Source* source) +{ + return static_cast<Target*>(source); +} + +void foo(OtherObject* other) +{ + dynamicDowncast<SubDerived>(other->obj()); +} diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp index a56c4222adb514a..716219836e6b445 100644 --- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp +++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp @@ -262,22 +262,6 @@ namespace param_forwarding_method { } } -namespace make_ref { - void makeRef(RefCountable*) {} - void makeRefPtr(RefCountable*) {} - void makeWeakPtr(RefCountable*) {} - void makeWeakPtr(RefCountable&) {} - - void foo() { - makeRef(provide()); - makeRefPtr(provide()); - RefPtr<RefCountable> a(provide()); - Ref<RefCountable> b(provide()); - makeWeakPtr(provide()); - makeWeakPtr(*provide()); - } -} - namespace downcast { void consume_ref_countable(RefCountable*) {} RefCountable* downcast(RefCountable*) { return nullptr; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits