diff --git a/sycl/test/regression/private_array_init_test.cpp b/sycl/test/regression/private_array_init_test.cpp new file mode 100644 index 0000000000000..d85a610794b03 --- /dev/null +++ b/sycl/test/regression/private_array_init_test.cpp @@ -0,0 +1,50 @@ +// RUN: %clangxx -fsycl %s -o %t.out -lOpenCL + +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +//==- private_array_init_test.cpp - Regression test for private array init -==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +namespace s = cl::sycl; + +class A { +public: + A() : _arr{0, 0, 0} {} + + size_t size() { + return sizeof(_arr) / sizeof(_arr[0]); + } + +private: + size_t _arr[3]; +}; + +int main() { + size_t data = 1; + + s::queue q; + { + s::buffer buf(&data, s::range<1>(1)); + q.submit([&](s::handler &cgh) { + auto acc = buf.get_access(cgh); + cgh.single_task([=]() { + // Test that SYCL program is not crashed if it contains a class/struct + // that has private array member which is initialized by zeroes. + acc[0] += A().size(); + }); + }); + } + + assert(data == 4); + + return 0; +}