Skip to content

Commit 05670b2

Browse files
[SYCL] Fix mismatched-new-delete warning in compression.hpp (#16483)
Fixed the following warning when DPC++ is built in Release mode with gcc 13: ``` In member function 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = char]', inlined from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = char; _Dp = std::default_delete<char>]' at /usr/include/c++/13/bits/unique_ptr.h:404:17, inlined from 'static std::unique_ptr<char> sycl::_V1::detail::ZSTDCompressor::DecompressBlob(const char*, size_t, size_t&)' at /tmp/llvm/sycl/source/detail/compression.hpp:139:3, inlined from 'void sycl::_V1::detail::CompressedRTDeviceBinaryImage::Decompress()' at /tmp/llvm/sycl/source/detail/device_binary_image.cpp:258:54: /usr/include/c++/13/bits/unique_ptr.h:99:9: error: 'void operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete] 99 | delete __ptr; | ^~~~~~~~~~~~ In file included from /tmp/llvm/sycl/source/detail/device_binary_image.cpp:13: In static member function 'static std::unique_ptr<char> sycl::_V1::detail::ZSTDCompressor::DecompressBlob(const char*, size_t, size_t&)', inlined from 'void sycl::_V1::detail::CompressedRTDeviceBinaryImage::Decompress()' at /tmp/llvm/sycl/source/detail/device_binary_image.cpp:258:54: /tmp/llvm/sycl/source/detail/compression.hpp:119:66: note: returned from 'void* operator new [](std::size_t)' 119 | auto dstBuffer = std::unique_ptr<char>(new char[dstBufferSize]); ``` Found in: #16463 (comment)
1 parent 092cd2d commit 05670b2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

sycl/source/detail/compression.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class ZSTDCompressor {
4141
public:
4242
// Blob (de)compression do not assume format/structure of the input buffer.
4343
// This function can be used in future for compression in on-disk cache.
44-
static std::unique_ptr<char> CompressBlob(const char *src, size_t srcSize,
45-
size_t &dstSize, int level) {
44+
static std::unique_ptr<char[]> CompressBlob(const char *src, size_t srcSize,
45+
size_t &dstSize, int level) {
4646
auto &instance = GetSingletonInstance();
4747

4848
// Lazy initialize compression context.
@@ -61,7 +61,7 @@ class ZSTDCompressor {
6161

6262
// Get maximum size of the compressed buffer and allocate it.
6363
auto dstBufferSize = ZSTD_compressBound(srcSize);
64-
auto dstBuffer = std::unique_ptr<char>(new char[dstBufferSize]);
64+
auto dstBuffer = std::make_unique<char[]>(dstBufferSize);
6565

6666
if (!dstBuffer)
6767
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
@@ -93,8 +93,8 @@ class ZSTDCompressor {
9393
return dstBufferSize;
9494
}
9595

96-
static std::unique_ptr<char> DecompressBlob(const char *src, size_t srcSize,
97-
size_t &dstSize) {
96+
static std::unique_ptr<char[]> DecompressBlob(const char *src, size_t srcSize,
97+
size_t &dstSize) {
9898
auto &instance = GetSingletonInstance();
9999

100100
// Lazy initialize decompression context.
@@ -116,7 +116,7 @@ class ZSTDCompressor {
116116
auto dstBufferSize = GetDecompressedSize(src, srcSize);
117117

118118
// Allocate buffer for decompressed data.
119-
auto dstBuffer = std::unique_ptr<char>(new char[dstBufferSize]);
119+
auto dstBuffer = std::make_unique<char[]>(dstBufferSize);
120120

121121
if (!dstBuffer)
122122
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),

sycl/source/detail/device_binary_image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class CompressedRTDeviceBinaryImage : public RTDeviceBinaryImage {
306306
}
307307

308308
private:
309-
std::unique_ptr<char> m_DecompressedData;
309+
std::unique_ptr<char[]> m_DecompressedData;
310310
size_t m_ImageSize;
311311
};
312312
#endif // SYCL_RT_ZSTD_NOT_AVAIABLE

0 commit comments

Comments
 (0)