diff options
author | Egor Churaev <egor.churaev@gmail.com> | 2017-04-05 12:47:10 +0000 |
---|---|---|
committer | Egor Churaev <egor.churaev@gmail.com> | 2017-04-05 12:47:10 +0000 |
commit | 3bccec5da7e553e4291ed5f1ad069fe68cb20a43 (patch) | |
tree | 071299c471a2866743b0b2200629ece0f1743bfb /clang/test | |
parent | 34e29784fbfa75fb654575657a7c149ac25d14c3 (diff) | |
download | bcm5719-llvm-3bccec5da7e553e4291ed5f1ad069fe68cb20a43.tar.gz bcm5719-llvm-3bccec5da7e553e4291ed5f1ad069fe68cb20a43.zip |
[OpenCL] Extended diagnostics for atomic initialization
Summary:
I saw the same changes in the following review: https://reviews.llvm.org/D17438
I don't know in that way I could determine that atomic variable was initialized by macro ATOMIC_VAR_INIT. Anyway I added check that atomic variables can be initialize only in global scope.
I think that we can discuss this change.
Reviewers: Anastasia, cfe-commits
Reviewed By: Anastasia
Subscribers: bader, yaxunl
Differential Revision: https://reviews.llvm.org/D30643
llvm-svn: 299537
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Parser/opencl-atomics-cl20.cl | 2 | ||||
-rw-r--r-- | clang/test/SemaOpenCL/atomic-init.cl | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/test/Parser/opencl-atomics-cl20.cl b/clang/test/Parser/opencl-atomics-cl20.cl index 65fb9d9b42a..ad67db0bab8 100644 --- a/clang/test/Parser/opencl-atomics-cl20.cl +++ b/clang/test/Parser/opencl-atomics-cl20.cl @@ -67,7 +67,7 @@ void atomic_ops_test() { foo(&i); // OpenCL v2.0 s6.13.11.8, arithemtic operations are not permitted on atomic types. i++; // expected-error {{invalid argument type 'atomic_int' (aka '_Atomic(int)') to unary expression}} - i = 1; // expected-error {{atomic variable can only be assigned to a compile time constant in the declaration statement in the program scope}} + i = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}} i += 1; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'int')}} i = i + i; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}} } diff --git a/clang/test/SemaOpenCL/atomic-init.cl b/clang/test/SemaOpenCL/atomic-init.cl new file mode 100644 index 00000000000..8208a85c3da --- /dev/null +++ b/clang/test/SemaOpenCL/atomic-init.cl @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s + +global atomic_int a1 = 0; + +kernel void test_atomic_initialization() { + a1 = 1; // expected-error {{atomic variable can be assigned to a variable only in global address space}} + atomic_int a2 = 0; // expected-error {{atomic variable can be initialized to a variable only in global address space}} + private atomic_int a3 = 0; // expected-error {{atomic variable can be initialized to a variable only in global address space}} + local atomic_int a4 = 0; // expected-error {{'__local' variable cannot have an initializer}} + global atomic_int a5 = 0; // expected-error {{function scope variable cannot be declared in global address space}} + static global atomic_int a6 = 0; +} |