diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 5487fea1b956c..797f3e1f3fba5 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -125,8 +125,9 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) { assert(F); const std::string &FunctionName = safeGetName(F); - return isRefType(FunctionName) || FunctionName == "adoptRef" || - FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" || + return isRefType(FunctionName) || FunctionName == "makeRef" || + FunctionName == "makeRefPtr" || FunctionName == "UniqueRef" || + FunctionName == "makeUniqueRef" || FunctionName == "makeUniqueRefWithoutFastMallocCheck" || FunctionName == "String" || FunctionName == "AtomString" || diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp b/clang/test/Analysis/Checkers/WebKit/call-args.cpp index b4613d5090f29..2146eae9975b9 100644 --- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp +++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp @@ -376,21 +376,3 @@ namespace call_with_explicit_temporary_obj { namespace call_with_explicit_construct { } - -namespace call_with_adopt_ref { - class Obj { - public: - void ref() const; - void deref() const; - void method(); - }; - - // This is needed due to rdar://141692212. - struct dummy { - RefPtr any; - }; - - void foo() { - adoptRef(new Obj)->method(); - } -} diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h b/clang/test/Analysis/Checkers/WebKit/mock-types.h index 0908e7fdb34dc..f3bd20f8bcf60 100644 --- a/clang/test/Analysis/Checkers/WebKit/mock-types.h +++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h @@ -74,10 +74,7 @@ template struct DefaultRefDerefTraits { template , typename RefDerefTraits = DefaultRefDerefTraits> struct Ref { typename PtrTraits::StorageType t; - enum AdoptTag { Adopt }; - Ref() : t{} {}; - Ref(T &t, AdoptTag) : t(&t) { } Ref(T &t) : t(&RefDerefTraits::ref(t)) { } Ref(const Ref& o) : t(RefDerefTraits::refIfNotNull(PtrTraits::unwrap(o.t))) { } Ref(Ref&& o) : t(o.leakRef()) { } @@ -104,19 +101,10 @@ template , typename RefDerefTra T* leakRef() { return PtrTraits::exchange(t, nullptr); } }; -template Ref adoptRef(T& t) { - using Ref = Ref; - return Ref(t, Ref::Adopt); -} - -template class RefPtr; -template RefPtr adoptRef(T*); - template struct RefPtr { T *t; - RefPtr() : t(nullptr) { } - + RefPtr() : t(new T) {} RefPtr(T *t) : t(t) { if (t) @@ -125,17 +113,6 @@ template struct RefPtr { RefPtr(Ref&& o) : t(o.leakRef()) { } - RefPtr(RefPtr&& o) - : t(o.t) - { - o.t = nullptr; - } - RefPtr(const RefPtr& o) - : t(o.t) - { - if (t) - t->ref(); - } ~RefPtr() { if (t) t->deref(); @@ -161,19 +138,8 @@ template struct RefPtr { return *this; } operator bool() const { return t; } - -private: - friend RefPtr adoptRef(T*); - - // call_with_adopt_ref in call-args.cpp requires this method to be private. - enum AdoptTag { Adopt }; - RefPtr(T *t, AdoptTag) : t(t) { } }; -template RefPtr adoptRef(T* t) { - return RefPtr(t, RefPtr::Adopt); -} - template bool operator==(const RefPtr &, const RefPtr &) { return false; } diff --git a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp index 4209db14eaa52..33c60ea8ca64d 100644 --- a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp +++ b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp @@ -61,6 +61,14 @@ template Function adopt(Detail::Callab return Function(impl, Function::Adopt); } +template, typename RefDerefTraits = DefaultRefDerefTraits> Ref adoptRef(T&); + +template +inline Ref adoptRef(T& reference) +{ + return Ref(reference); +} + enum class DestructionThread : unsigned char { Any, Main, MainRunLoop }; void ensureOnMainThread(Function&&); // Sync if called on main thread, async otherwise. void ensureOnMainRunLoop(Function&&); // Sync if called on main run loop, async otherwise.