From 882063b0e4595d1670b6cb2bc77971bb34a42e19 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Fri, 29 Jul 2022 11:04:23 -0500 Subject: [PATCH] Fixing component multiple inheritance - flyby: fixing get_ptr<>(sync) --- .../include/hpx/components/get_ptr.hpp | 3 +- .../tests/regressions/CMakeLists.txt | 22 +++- .../regressions/multiple_inheritance_5964.cpp | 107 ++++++++++++++++++ .../components_base/server/component_base.hpp | 2 +- 4 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 libs/full/components/tests/regressions/multiple_inheritance_5964.cpp diff --git a/libs/full/components/include/hpx/components/get_ptr.hpp b/libs/full/components/include/hpx/components/get_ptr.hpp index 5d5d95bb03b0..2f2cb55c4917 100644 --- a/libs/full/components/include/hpx/components/get_ptr.hpp +++ b/libs/full/components/include/hpx/components/get_ptr.hpp @@ -253,7 +253,8 @@ namespace hpx { naming::get_locality_id_from_gid(gid) == agas::get_locality_id(ec)) { return std::shared_ptr( - get_lva::call(gid.get_lsb()), + get_lva::call( + reinterpret_cast(gid.get_lsb())), detail::get_ptr_no_unpin_deleter(id)); } diff --git a/libs/full/components/tests/regressions/CMakeLists.txt b/libs/full/components/tests/regressions/CMakeLists.txt index 2f7420810a42..58c7a86eac16 100644 --- a/libs/full/components/tests/regressions/CMakeLists.txt +++ b/libs/full/components/tests/regressions/CMakeLists.txt @@ -1,5 +1,25 @@ -# Copyright (c) 2020-2021 The STE||AR-Group +# Copyright (c) 2022 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +set(tests multiple_inheritance_5964) + +foreach(test ${tests}) + set(sources ${test}.cpp) + + source_group("Source Files" FILES ${sources}) + + set(folder_name "Tests/Regressions/Modules/Full/Components") + + # add example executable + add_hpx_executable( + ${test}_test INTERNAL_FLAGS + SOURCES ${sources} ${${test}_FLAGS} + EXCLUDE_FROM_ALL + FOLDER ${folder_name} + ) + + add_hpx_regression_test("modules.components" ${test} ${${test}_PARAMETERS}) +endforeach() diff --git a/libs/full/components/tests/regressions/multiple_inheritance_5964.cpp b/libs/full/components/tests/regressions/multiple_inheritance_5964.cpp new file mode 100644 index 000000000000..3f9bea405990 --- /dev/null +++ b/libs/full/components/tests/regressions/multiple_inheritance_5964.cpp @@ -0,0 +1,107 @@ +// Copyright (c) 2022 Joseph Kleinhenz +// +// SPDX-License-Identifier: BSL-1.0 +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// This test illustrates the problem reported by #5964: component with multiple +// inheritance + +#include + +#if !defined(HPX_COMPUTE_DEVICE_CODE) +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +struct foo_t +{ + int a; + int b; + + foo_t() = default; + foo_t(int a, int b) + : a(a) + , b(b) + { + } + + friend class hpx::serialization::access; + template + inline void serialize(Archive& ar, const unsigned int) + { + // clang-format off + ar & a & b; + // clang-format on + } +}; + +struct component_server + : hpx::components::component_base + , foo_t +{ + explicit component_server(foo_t foo) + : foo_t(std::move(foo)) + { + } +}; + +HPX_REGISTER_COMPONENT( + hpx::components::component, component_server_component) + +struct component_server2 + : foo_t + , hpx::components::component_base + +{ + explicit component_server2(foo_t foo) + : foo_t(std::move(foo)) + { + } +}; + +HPX_REGISTER_COMPONENT( + hpx::components::component, component_server2_component) + +int hpx_main() +{ + foo_t in{1, 2}; + + { + hpx::id_type id = + hpx::new_(hpx::find_here(), in).get(); + auto out = hpx::get_ptr(hpx::launch::sync, id); + + HPX_TEST_EQ(out->a, in.a); + HPX_TEST_EQ(out->b, in.b); + } + + { + hpx::id_type id = + hpx::new_(hpx::find_here(), in).get(); + auto out = hpx::get_ptr(hpx::launch::sync, id); + + HPX_TEST_EQ(out->a, in.a); + HPX_TEST_EQ(out->b, in.b); + } + + return hpx::finalize(); +} + +int main(int argc, char** argv) +{ + HPX_TEST_EQ(hpx::init(argc, argv), 0); + return hpx::util::report_errors(); +} + +#endif diff --git a/libs/full/components_base/include/hpx/components_base/server/component_base.hpp b/libs/full/components_base/include/hpx/components_base/server/component_base.hpp index 8ad1afd970fa..399186b4ac48 100644 --- a/libs/full/components_base/include/hpx/components_base/server/component_base.hpp +++ b/libs/full/components_base/include/hpx/components_base/server/component_base.hpp @@ -116,7 +116,7 @@ namespace hpx { namespace components { return naming::address( naming::get_gid_from_locality_id(agas::get_locality_id()), components::get_component_type(), - const_cast(this)); + const_cast(static_cast(this))); } hpx::id_type get_id() const