diff --git a/sycl/test-e2e/AddressSanitizer/memory-leak/memory-leak-shared-lib.cpp b/sycl/test-e2e/AddressSanitizer/memory-leak/memory-leak-shared-lib.cpp new file mode 100644 index 0000000000000..60d6326a60eb0 --- /dev/null +++ b/sycl/test-e2e/AddressSanitizer/memory-leak/memory-leak-shared-lib.cpp @@ -0,0 +1,37 @@ +// REQUIRES: linux, cpu +// RUN: %{build} %device_asan_flags -O0 -g -fPIC -shared -DSHARED_LIB -o %t.so +// RUN: %{build} %device_asan_flags -O0 -g -fPIC -Wl,-rpath,. %t.so -o %t +// RUN: %{run} %t 2>&1 | FileCheck %s +#include + +#include + +#if defined(SHARED_LIB) +void test(sycl::queue &Q, size_t N) { + auto *array = sycl::malloc_device(N, Q); + + Q.submit([&](sycl::handler &h) { + h.parallel_for( + sycl::nd_range<1>(N, 1), + [=](sycl::nd_item<1> item) { ++array[item.get_global_id(0)]; }); + }).wait(); +} + +#else + +void test(sycl::queue &Q, size_t N); + +int main() { + sycl::queue Q; + constexpr std::size_t N = 12; + + test(Q, N); + + // CHECK: ERROR: DeviceSanitizer: detected memory leaks of Device USM + // CHECK: Direct leak of 12 byte(s) at {{0x.*}} allocated from: + // CHECK: in test{{.*memory-leak-shared-lib.cpp:}}[[@LINE-21]] + + return 0; +} + +#endif