Skip to content
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

Fix read of dangling reference in thrust placeholders #2290

Merged
merged 1 commit into from
Aug 26, 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
23 changes: 10 additions & 13 deletions thrust/testing/functional_placeholders_miscellaneous.cu
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,14 @@ VectorUnitTest<TestFunctionalPlaceholdersTransformIterator,
VectorUnitTest<TestFunctionalPlaceholdersTransformIterator, ThirtyTwoBitTypes, thrust::host_vector, std::allocator>
TestFunctionalPlaceholdersTransformIteratorInstanceHost;

template <typename T>
struct TestFunctionalPlaceholdersArgumentValueCategories
void TestFunctionalPlaceholdersArgumentValueCategories()
{
void operator()() const
{
using namespace thrust::placeholders;
auto expr = _1 * _1 + _2 * _2;
T a = 2;
T b = 3;
ASSERT_ALMOST_EQUAL(expr(2, 3), 13); // pass pr-value
ASSERT_ALMOST_EQUAL(expr(a, b), 13); // pass l-value
ASSERT_ALMOST_EQUAL(expr(::cuda::std::move(a), ::cuda::std::move(b)), 13); // pass x-value
}
};
using namespace thrust::placeholders;
auto expr = _1 * _1 + _2 * _2;
int a = 2;
int b = 3;
ASSERT_EQUAL(expr(2, 3), 13); // pass pr-value
ASSERT_EQUAL(expr(a, b), 13); // pass l-value
ASSERT_EQUAL(expr(::cuda::std::move(a), ::cuda::std::move(b)), 13); // pass x-value
}
DECLARE_UNITTEST(TestFunctionalPlaceholdersArgumentValueCategories);
4 changes: 2 additions & 2 deletions thrust/thrust/detail/functional/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ struct argument
{
template <typename... Ts>
_CCCL_HOST_DEVICE auto
eval(Ts&&... args) const -> decltype(thrust::get<Pos>(thrust::tuple<Ts...>{THRUST_FWD(args)...}))
eval(Ts&&... args) const -> decltype(thrust::get<Pos>(thrust::tuple<Ts&&...>{THRUST_FWD(args)...}))
{
return thrust::get<Pos>(thrust::tuple<Ts...>{THRUST_FWD(args)...});
return thrust::get<Pos>(thrust::tuple<Ts&&...>{THRUST_FWD(args)...});
}
};

Expand Down
Loading