https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/224464
None >From f9b0e4ef37ea25e271210fa9360cb04647981a0e Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa <[email protected]> Date: Thu, 17 Sep 2026 15:45:41 -0700 Subject: [PATCH] Revert bf005a1. Caused too many new warnings. --- .../Checkers/WebKit/ASTUtils.cpp | 11 +- .../Checkers/WebKit/PtrTypesSemantics.cpp | 4 +- .../Analysis/Checkers/WebKit/call-args.cpp | 42 ++++ .../Checkers/WebKit/objc-mock-types.h | 4 - .../WebKit/unretained-call-args-member.mm | 184 ------------------ 5 files changed, 47 insertions(+), 198 deletions(-) delete mode 100644 clang/test/Analysis/Checkers/WebKit/unretained-call-args-member.mm diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index e8f69f1aac757..bf625be2ab6e3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -111,14 +111,9 @@ bool tryToFindPtrOrigin( if (auto *decl = memberCall->getMethodDecl()) { std::optional<bool> IsGetterOfRefCt = isGetterOfSafePtr(decl); if (IsGetterOfRefCt && *IsGetterOfRefCt) { - E = memberCall->getImplicitObjectArgument()->IgnoreParenCasts(); - if (auto *DRE = dyn_cast<DeclRefExpr>(E)) { - if (auto *Decl = dyn_cast_or_null<VarDecl>(DRE->getDecl())) { - if (Decl->isLocalVarDeclOrParm()) { - if (StopAtFirstRefCountedObj) - return callback(E, true); - } - } + E = memberCall->getImplicitObjectArgument(); + if (StopAtFirstRefCountedObj) { + return callback(E, true); } continue; } diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 37347c51d4ca2..a71b979294c1e 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -139,8 +139,8 @@ bool isCheckedPtr(const std::string &Name) { } bool isOwnerPtr(const std::string &Name) { - return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) || - Name == "unique_ptr" || Name == "UniqueRef" || Name == "LazyUniqueRef"; + return isRefType(Name) || isCheckedPtr(Name) || Name == "unique_ptr" || + Name == "UniqueRef" || Name == "LazyUniqueRef"; } static bool isWeakPtrClass(const std::string &Name) { diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp index 5e9f1591692e6..228eb85128c6d 100644 --- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp +++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp @@ -553,6 +553,48 @@ namespace call_on_member { } +namespace call_on_member { + + class SomeObj { + public: + static Ref<SomeObj> create() { return adoptRef(*new SomeObj); } + + void ref() const; + void deref() const; + + void doWork() { + m_obj->method(); + // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} + m_obj.get()->method(); + // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} + m_constObj->method(); + } + + void localWork() { + RefPtr obj = provide(); + obj->method(); + obj.get()->method(); + } + + void argWork(RefPtr<RefCountable> arg) { + arg->method(); + arg.get()->method(); + } + + void temporaryWork() { + RefPtr { provide() }->method(); + RefPtr { provide() }.get()->method(); + } + + void work(); + + private: + RefPtr<RefCountable> m_obj; + const RefPtr<RefCountable> m_constObj; + }; + +} + namespace call_with_weak_ptr { class RefCountableWithWeakPtr : public RefCountable, public CanMakeWeakPtr<RefCountableWithWeakPtr> { diff --git a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h index aad2a6185d0b0..b0cbf0756c2d0 100644 --- a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h +++ b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h @@ -449,9 +449,6 @@ template<typename T> static inline void releaseOSObject(T ptr) template<typename T> class OSObjectPtr { public: - using ValueType = typename RemovePointer<T>::Type; - using PtrType = ValueType*; - OSObjectPtr() : m_ptr(nullptr) { @@ -465,7 +462,6 @@ template<typename T> class OSObjectPtr { T get() const { return m_ptr; } - operator PtrType() const { return m_ptr; } explicit operator bool() const { return m_ptr; } bool operator!() const { return !m_ptr; } diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-member.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args-member.mm deleted file mode 100644 index d680b2e348670..0000000000000 --- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-member.mm +++ /dev/null @@ -1,184 +0,0 @@ -// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}} -// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UnretainedCallArgsChecker -verify %s - -#include "objc-mock-types.h" - -void consume_cf(CFMutableArrayRef); -void consume_obj(SomeObj *); - -namespace call_args_const_retainptr_member { - -class Foo { -public: - Foo(); - void bar(); - -private: - const RetainPtr<SomeObj> m_constObj; - RetainPtr<SomeObj> m_obj; -}; - -void Foo::bar() { - [m_constObj doWork]; // no-warning - [m_obj doWork]; // expected-warning{{Receiver 'this->m_obj' (to '-[SomeObj doWork]') is a raw pointer to RetainPtr-capable type 'SomeObj'}} -} - -} // namespace call_args_const_retainptr_member - -namespace call_args_const_retainptr_cf_member { - -class Foo { -public: - Foo(); - void bar(); - -private: - const RetainPtr<CFMutableArrayRef> m_cf1; - RetainPtr<CFMutableArrayRef> m_cf2; -}; - -void Foo::bar() { - consume_cf(m_cf1.get()); // no-warning - consume_cf(m_cf2.get()); // expected-warning{{Function argument 'this->m_cf2.get()' (to 'consume_cf') is a RetainPtr-capable type 'CFArrayRef'}} -} - -} // namespace call_args_const_retainptr_cf_member - -namespace call_args_const_retainptr_struct_member { - -struct Bar { - Bar(); - void baz(); - - const RetainPtr<SomeObj> m_constObj; - RetainPtr<SomeObj> m_obj; -}; - -void Bar::baz() { - [m_constObj doWork]; // no-warning - [m_obj doWork]; // expected-warning{{Receiver 'this->m_obj' (to '-[SomeObj doWork]') is a raw pointer to RetainPtr-capable type 'SomeObj'}} -} - -} // namespace call_args_const_retainptr_struct_member - -namespace call_args_const_retainptr_cf_struct_member { - -struct Bar { - Bar(); - void baz(); - - const RetainPtr<CFMutableArrayRef> m_cf1; - RetainPtr<CFMutableArrayRef> m_cf2; -}; - -void Bar::baz() { - consume_cf(m_cf1.get()); // no-warning - consume_cf(m_cf2.get()); // expected-warning{{Function argument 'this->m_cf2.get()' (to 'consume_cf') is a RetainPtr-capable type 'CFArrayRef'}} -} - -} // namespace call_args_const_retainptr_cf_struct_member - -namespace call_args_const_retainptr_get_as_objc_arg { - -class Foo { -public: - Foo(); - void bar(); - -private: - const RetainPtr<SomeObj> m_constObj; - RetainPtr<SomeObj> m_obj; -}; - -void Foo::bar() { - consume_obj(m_constObj.get()); // no-warning - consume_obj(m_obj.get()); // expected-warning{{Function argument 'this->m_obj.get()' (to 'consume_obj') is a RetainPtr-capable type 'WTF::RetainPtr<SomeObj>::PtrType'}} -} - -} // namespace call_args_const_retainptr_get_as_objc_arg - -namespace call_args_const_retainptr_implicit_conv_arg { - -class Foo { -public: - Foo(); - void bar(); - -private: - const RetainPtr<SomeObj> m_constObj; - RetainPtr<SomeObj> m_obj; -}; - -void Foo::bar() { - consume_obj(m_constObj); // no-warning - consume_obj(m_obj); // expected-warning{{Function argument 'this->m_obj' (to 'consume_obj') is a RetainPtr-capable type 'WTF::RetainPtr<SomeObj>::PtrType'}} -} - -} // namespace call_args_const_retainptr_implicit_conv_arg - -namespace call_args_const_osobjectptr_member { - -class Foo { -public: - Foo(); - void bar(); - -private: - const OSObjectPtr<SomeObj *> m_constObj; - OSObjectPtr<SomeObj *> m_obj; -}; - -void Foo::bar() { - consume_obj(m_constObj.get()); // no-warning - consume_obj(m_obj.get()); // expected-warning{{Function argument 'this->m_obj.get()' (to 'consume_obj') is a raw pointer to RetainPtr-capable type 'SomeObj'}} -} - -} // namespace call_args_const_osobjectptr_member - -namespace call_args_const_osobjectptr_receiver { - -class Foo { -public: - Foo(); - void bar(); - -private: - const OSObjectPtr<SomeObj *> m_constObj; - OSObjectPtr<SomeObj *> m_obj; -}; - -void Foo::bar() { - [m_constObj doWork]; // no-warning - [m_obj doWork]; // expected-warning{{Receiver 'this->m_obj' (to '-[SomeObj doWork]') is a raw pointer to RetainPtr-capable type 'SomeObj'}} -} - -} // namespace call_args_const_osobjectptr_receiver - -namespace call_args_retainptr_local { - -void testLocal(SomeObj *input) { - RetainPtr<SomeObj> localObj = input; - [localObj doWork]; // no-warning - consume_obj(localObj.get()); // no-warning - consume_cf(RetainPtr<CFMutableArrayRef>().get()); // no-warning -} - -} // namespace call_args_retainptr_local - -namespace call_args_retainptr_protected_member { - -class Foo { -public: - Foo(); - void bar(); - -private: - RetainPtr<SomeObj> m_obj; -}; - -void Foo::bar() { - auto protectedObj = m_obj; - [protectedObj doWork]; // no-warning (local copy is safe) -} - -} // namespace call_args_retainptr_protected_member _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
