From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- build/clang-plugin/alpha/tests/TestNonStdMove.cpp | 125 ++++++++++++++++++++++ build/clang-plugin/alpha/tests/TestTempRefPtr.cpp | 52 +++++++++ build/clang-plugin/alpha/tests/sources.mozbuild | 11 ++ 3 files changed, 188 insertions(+) create mode 100644 build/clang-plugin/alpha/tests/TestNonStdMove.cpp create mode 100644 build/clang-plugin/alpha/tests/TestTempRefPtr.cpp create mode 100644 build/clang-plugin/alpha/tests/sources.mozbuild (limited to 'build/clang-plugin/alpha/tests') diff --git a/build/clang-plugin/alpha/tests/TestNonStdMove.cpp b/build/clang-plugin/alpha/tests/TestNonStdMove.cpp new file mode 100644 index 0000000000..379f9655dd --- /dev/null +++ b/build/clang-plugin/alpha/tests/TestNonStdMove.cpp @@ -0,0 +1,125 @@ +#include + +// we can't include nsCOMPtr.h here, so let's redefine a basic version +template +struct nsCOMPtr { + nsCOMPtr() = default; + + template + MOZ_IMPLICIT nsCOMPtr(already_AddRefed&& aSrc); + + template + nsCOMPtr& operator=(already_AddRefed&& aSrc); +}; + + +using namespace mozilla; + +struct RefCountedBase { + void AddRef(); + void Release(); + + void method_test(); +}; + +struct RefCountedDerived : RefCountedBase {}; + +struct RefCountedBaseHolder { + RefPtr GetRefCountedBase() const { + return mRefCountedBase; + } + +private: + RefPtr mRefCountedBase = MakeRefPtr(); +}; + + +void test_assign_same_type() { + RefPtr a = MakeRefPtr(); + RefPtr b; + + b = a.forget(); // expected-warning {{non-standard move assignment}} +} + +void test_assign_implicit_cast() { + RefPtr a = MakeRefPtr(); + RefPtr b; + + b = a.forget(); // expected-warning {{non-standard move assignment}} +} + +void test_assign_different_template() { + RefPtr a = MakeRefPtr(); + nsCOMPtr b; + + b = a.forget(); // expected-warning {{non-standard move assignment}} +} + +void test_construct_different_template() { + RefPtr a = MakeRefPtr(); + nsCOMPtr b = a.forget(); // expected-warning {{non-standard move construction}} +} + +void test_assign_already_addrefed() { + RefPtr a = MakeRefPtr(); + already_AddRefed b; + + b = a.forget(); +} + +void test_construct_already_addrefed() { + RefPtr a = MakeRefPtr(); + already_AddRefed b = a.forget(); +} + +void test_construct_same_type() { + RefPtr a = MakeRefPtr(); + RefPtr b = a.forget(); // expected-warning {{non-standard move construction}} +} + +void test_construct_implicit_cast() { + RefPtr a = MakeRefPtr(); + RefPtr b = a.forget(); // expected-warning {{non-standard move construction}} +} + +void test_construct_brace_same_type() { + RefPtr a = MakeRefPtr(); + auto b = RefPtr{a.forget()}; // expected-warning {{non-standard move construction}} +} + +void test_construct_brace_implicit_cast() { + RefPtr a = MakeRefPtr(); + auto b = RefPtr{a.forget()}; // expected-warning {{non-standard move construction}} +} + +void test_construct_function_style_same_type() { + RefPtr a = MakeRefPtr(); + auto b = RefPtr(a.forget()); // expected-warning {{non-standard move construction}} +} + +void test_construct_function_style_implicit_cast() { + RefPtr a = MakeRefPtr(); + auto b = RefPtr(a.forget()); // expected-warning {{non-standard move construction}} +} + +void test_construct_result_type() { + RefPtr a = MakeRefPtr(); + already_AddRefed b = a.forget(); +} + +void test_construct_implicitly_cast_result_type() { + RefPtr a = MakeRefPtr(); + already_AddRefed b = a.forget(); +} + +void foo(already_AddRefed&& aArg); + +void test_call_with_result_type() { + RefPtr a = MakeRefPtr(); + foo(a.forget()); +} + +void test_call_with_implicitly_cast_result_type() { + RefPtr a = MakeRefPtr(); + foo(a.forget()); +} diff --git a/build/clang-plugin/alpha/tests/TestTempRefPtr.cpp b/build/clang-plugin/alpha/tests/TestTempRefPtr.cpp new file mode 100644 index 0000000000..51f756b8e6 --- /dev/null +++ b/build/clang-plugin/alpha/tests/TestTempRefPtr.cpp @@ -0,0 +1,52 @@ +#include + +using namespace mozilla; + +struct RefCountedBase { + void AddRef(); + void Release(); + + void method_test(); +}; + +struct RefCountedBaseHolder { + RefPtr GetRefCountedBase() const { + return mRefCountedBase; + } + +private: + RefPtr mRefCountedBase = MakeRefPtr(); +}; + + +void test_arrow_temporary_new_refptr_function_style_cast() { + RefPtr(new RefCountedBase())->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} +} + +void test_arrow_temporary_new_refptr_brace() { + RefPtr{new RefCountedBase()}->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} +} + +void test_arrow_temporary_new_c_style_cast() { + ((RefPtr)(new RefCountedBase()))->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} +} + +void test_arrow_temporary_new_static_cast() { + static_cast>(new RefCountedBase())->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} +} + +void test_arrow_temporary_new_refptr_makerefptr() { + MakeRefPtr()->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} +} + +void test_arrow_temporary_get_refptr_from_member_function() { + const RefCountedBaseHolder holder; + holder.GetRefCountedBase()->method_test(); // expected-warning {{performance issue: temporary 'RefPtr' is only dereferenced here once which involves short-lived AddRef/Release calls}} expected-note {{consider changing function RefCountedBaseHolder::GetRefCountedBase to return a raw reference instead}} +} + +void test_ref(RefCountedBase &aRefCountedBase); + +void test_star_temporary_new_refptr_function_style_cast() { + // TODO: Should we warn about operator* as well? + test_ref(*RefPtr(new RefCountedBase())); +} diff --git a/build/clang-plugin/alpha/tests/sources.mozbuild b/build/clang-plugin/alpha/tests/sources.mozbuild new file mode 100644 index 0000000000..b72cacd253 --- /dev/null +++ b/build/clang-plugin/alpha/tests/sources.mozbuild @@ -0,0 +1,11 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +SOURCES += [ + # 'AlphaTest.cpp', + "TestNonStdMove.cpp", + 'TestTempRefPtr.cpp', +] -- cgit v1.2.3