Skip to content

Commit 3e1fb14

Browse files
authored
[SYCL] Add test for private array init by zeroes (#1402)
Test checks that SYCL program is not crashed if it contains a class/struct that has private array member which is initialized by zeroes. Signed-off-by: Mikhail Lychkov <mikhail.lychkov@intel.com>
1 parent ba404be commit 3e1fb14

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out -lOpenCL
2+
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
//==- private_array_init_test.cpp - Regression test for private array init -==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
17+
namespace s = cl::sycl;
18+
19+
class A {
20+
public:
21+
A() : _arr{0, 0, 0} {}
22+
23+
size_t size() {
24+
return sizeof(_arr) / sizeof(_arr[0]);
25+
}
26+
27+
private:
28+
size_t _arr[3];
29+
};
30+
31+
int main() {
32+
size_t data = 1;
33+
34+
s::queue q;
35+
{
36+
s::buffer<size_t, 1> buf(&data, s::range<1>(1));
37+
q.submit([&](s::handler &cgh) {
38+
auto acc = buf.get_access<s::access::mode::read_write>(cgh);
39+
cgh.single_task<class test>([=]() {
40+
// Test that SYCL program is not crashed if it contains a class/struct
41+
// that has private array member which is initialized by zeroes.
42+
acc[0] += A().size();
43+
});
44+
});
45+
}
46+
47+
assert(data == 4);
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)