[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -verify -fsyntax-only
|
|
|
|
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -verify -fsyntax-only -fexceptions -fcxx-exceptions
|
|
|
|
|
|
|
|
// This test checks that various C++ and OpenCL C keywords are not available
|
2019-07-18 18:02:35 +08:00
|
|
|
// in OpenCL.
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
|
|
|
|
// Test that exceptions are disabled despite passing -fcxx-exceptions.
|
|
|
|
kernel void test_exceptions() {
|
|
|
|
int x;
|
|
|
|
try {
|
|
|
|
// expected-error@-1 {{cannot use 'try' with exceptions disabled}}
|
|
|
|
throw 0;
|
|
|
|
// expected-error@-1 {{cannot use 'throw' with exceptions disabled}}
|
|
|
|
} catch (int i) {
|
|
|
|
x = 41;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that only __-prefixed address space qualifiers are accepted.
|
|
|
|
struct test_address_space_qualifiers {
|
|
|
|
global int *g;
|
|
|
|
__global int *uug;
|
2019-03-25 19:54:02 +08:00
|
|
|
int global; // expected-warning{{declaration does not declare anything}}
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
|
|
|
|
local int *l;
|
|
|
|
__local int *uul;
|
2019-03-25 19:54:02 +08:00
|
|
|
int local; // expected-warning{{declaration does not declare anything}}
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
|
|
|
|
private int *p;
|
|
|
|
__private int *uup;
|
2019-03-25 19:54:02 +08:00
|
|
|
int private; // expected-warning{{declaration does not declare anything}}
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
|
|
|
|
constant int *c;
|
|
|
|
__constant int *uuc;
|
2019-03-25 19:54:02 +08:00
|
|
|
int constant; // expected-warning{{declaration does not declare anything}}
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
|
|
|
|
generic int *ge;
|
|
|
|
__generic int *uuge;
|
2019-03-25 19:54:02 +08:00
|
|
|
int generic; // expected-warning{{declaration does not declare anything}}
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
};
|
2019-03-25 19:54:02 +08:00
|
|
|
|
|
|
|
// Test that 'private' can be parsed as an access qualifier and an address space too.
|
|
|
|
class A{
|
|
|
|
private:
|
|
|
|
private int i; //expected-error{{field may not be qualified with an address space}}
|
|
|
|
};
|
|
|
|
|
|
|
|
private ::A i; //expected-error{{program scope variable must reside in global or constant address space}}
|
|
|
|
|
|
|
|
void foo(private int i);
|
|
|
|
|
|
|
|
private int bar(); //expected-error{{return value cannot be qualified with address space}}
|