Skip to content

Revert "[WebKit checkers] Recognize adoptRef as a safe function" #120626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" ||
Expand Down
18 changes: 0 additions & 18 deletions clang/test/Analysis/Checkers/WebKit/call-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Obj> any;
};

void foo() {
adoptRef(new Obj)->method();
}
}
36 changes: 1 addition & 35 deletions clang/test/Analysis/Checkers/WebKit/mock-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ template<typename T> struct DefaultRefDerefTraits {
template <typename T, typename PtrTraits = RawPtrTraits<T>, typename RefDerefTraits = DefaultRefDerefTraits<T>> 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()) { }
Expand All @@ -104,19 +101,10 @@ template <typename T, typename PtrTraits = RawPtrTraits<T>, typename RefDerefTra
T* leakRef() { return PtrTraits::exchange(t, nullptr); }
};

template <typename T> Ref<T> adoptRef(T& t) {
using Ref = Ref<T>;
return Ref(t, Ref::Adopt);
}

template<typename T> class RefPtr;
template<typename T> RefPtr<T> adoptRef(T*);

template <typename T> struct RefPtr {
T *t;

RefPtr() : t(nullptr) { }

RefPtr() : t(new T) {}
RefPtr(T *t)
: t(t) {
if (t)
Expand All @@ -125,17 +113,6 @@ template <typename T> struct RefPtr {
RefPtr(Ref<T>&& 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();
Expand All @@ -161,19 +138,8 @@ template <typename T> struct RefPtr {
return *this;
}
operator bool() const { return t; }

private:
friend RefPtr adoptRef<T>(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 <typename T> RefPtr<T> adoptRef(T* t) {
return RefPtr<T>(t, RefPtr<T>::Adopt);
}

template <typename T> bool operator==(const RefPtr<T> &, const RefPtr<T> &) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ template<typename Out, typename... In> Function<Out(In...)> adopt(Detail::Callab
return Function<Out(In...)>(impl, Function<Out(In...)>::Adopt);
}

template<typename T, typename PtrTraits = RawPtrTraits<T>, typename RefDerefTraits = DefaultRefDerefTraits<T>> Ref<T, PtrTraits, RefDerefTraits> adoptRef(T&);

template<typename T, typename _PtrTraits, typename RefDerefTraits>
inline Ref<T, _PtrTraits, RefDerefTraits> adoptRef(T& reference)
{
return Ref<T, _PtrTraits, RefDerefTraits>(reference);
}

enum class DestructionThread : unsigned char { Any, Main, MainRunLoop };
void ensureOnMainThread(Function<void()>&&); // Sync if called on main thread, async otherwise.
void ensureOnMainRunLoop(Function<void()>&&); // Sync if called on main run loop, async otherwise.
Expand Down
Loading