Skip to content

Commit d5058e2

Browse files
authored
[SYCL] Fix element type in handler::copy (#2590)
The original motivation for the fix was a SegFault reported in such trivial case on Linux: #include <memory> #include <iostream> struct A { A() { std::cout << "Init\n"; } ~A() { std::cout << "Free\n"; } }; int main() { { std::cout << "good1:\n"; std::shared_ptr<A[]> good1(new A[5]); } { std::cout << "good2:\n"; std::shared_ptr<A> good2(new A[5], [](A *p) {delete[] p;}); } { std::cout << "baad1:\n"; std::shared_ptr<A> baad1(new A[5]); } return 0; } Fixing the LIT test that had similar bad pattern code revealed a weakness in handler.hpp, which was also fixed. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 8149957 commit d5058e2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sycl/include/CL/sycl/handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ class __SYCL_EXPORT handler {
15891589
// Make sure data shared_ptr points to is not released until we finish
15901590
// work with it.
15911591
MSharedPtrStorage.push_back(Dst);
1592-
T_Dst *RawDstPtr = Dst.get();
1592+
typename shared_ptr_class<T_Dst>::element_type *RawDstPtr = Dst.get();
15931593
copy(Src, RawDstPtr);
15941594
}
15951595

@@ -1612,7 +1612,7 @@ class __SYCL_EXPORT handler {
16121612
// Make sure data shared_ptr points to is not released until we finish
16131613
// work with it.
16141614
MSharedPtrStorage.push_back(Src);
1615-
T_Src *RawSrcPtr = Src.get();
1615+
typename shared_ptr_class<T_Src>::element_type *RawSrcPtr = Src.get();
16161616
copy(RawSrcPtr, Dst);
16171617
}
16181618

sycl/test/basic_tests/handler/handler_mem_op.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ template <typename T> void test_copy_acc_ptr() {
348348
template <typename T> void test_copy_shared_ptr_acc() {
349349
const size_t Size = 10;
350350
T Data[Size] = {0};
351-
std::shared_ptr<T> Values(new T[Size]());
351+
std::shared_ptr<T[]> Values(new T[Size]());
352352
for (size_t I = 0; I < Size; ++I) {
353353
Values.get()[I] = I;
354354
}
@@ -369,7 +369,7 @@ template <typename T> void test_copy_shared_ptr_acc() {
369369
template <typename T> void test_copy_shared_ptr_const_acc() {
370370
constexpr size_t Size = 10;
371371
T Data[Size] = {0};
372-
std::shared_ptr<const T> Values(new T[Size]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
372+
std::shared_ptr<const T[]> Values(new T[Size]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
373373
{
374374
buffer<T, 1> Buffer(Data, range<1>(Size));
375375
queue Queue;
@@ -390,7 +390,7 @@ template <typename T> void test_copy_acc_shared_ptr() {
390390
for (size_t I = 0; I < Size; ++I) {
391391
Data[I] = I;
392392
}
393-
std::shared_ptr<T> Values(new T[Size]());
393+
std::shared_ptr<T[]> Values(new T[Size]());
394394
{
395395
buffer<T, 1> Buffer(Data, range<1>(Size));
396396
queue Queue;

0 commit comments

Comments
 (0)