Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only %s |
Sven van Haastregt | 1076cc2 | 2018-09-20 10:07:27 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 3 | |
| 4 | void test(void) { |
| 5 | global int *glob; |
| 6 | local int *loc; |
| 7 | constant int *con; |
Sven van Haastregt | d1f3002 | 2018-09-27 13:20:29 +0000 | [diff] [blame] | 8 | private int *priv; |
| 9 | global float *glob_wrong_ty; |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 10 | typedef constant int const_int_ty; |
| 11 | const_int_ty *con_typedef; |
| 12 | |
| 13 | glob = to_global(glob, loc); |
| 14 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | ae2e86f | 2018-09-24 14:21:56 +0000 | [diff] [blame] | 15 | // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}} |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 16 | // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 17 | #else |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 18 | // expected-error@-5{{invalid number of arguments to function: 'to_global'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 19 | #endif |
| 20 | |
| 21 | int x; |
| 22 | glob = to_global(x); |
| 23 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 24 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 25 | #else |
| 26 | // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}} |
| 27 | #endif |
| 28 | |
| 29 | glob = to_global(con); |
| 30 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 31 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 32 | #else |
| 33 | // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}} |
| 34 | #endif |
| 35 | |
| 36 | glob = to_global(con_typedef); |
| 37 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 38 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 39 | #else |
| 40 | // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}} |
| 41 | #endif |
| 42 | |
| 43 | loc = to_global(glob); |
| 44 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 45 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 46 | #else |
| 47 | // expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}} |
Sven van Haastregt | 1076cc2 | 2018-09-20 10:07:27 +0000 | [diff] [blame] | 48 | // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Sven van Haastregt | d1f3002 | 2018-09-27 13:20:29 +0000 | [diff] [blame] | 51 | loc = to_private(glob); |
| 52 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 53 | // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}} |
| 54 | // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}} |
| 55 | #else |
| 56 | // expected-error@-5{{assigning 'int *' to '__local int *' changes address space of pointer}} |
| 57 | // expected-warning@-6{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}} |
| 58 | #endif |
| 59 | |
| 60 | loc = to_local(glob); |
| 61 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 62 | // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}} |
| 63 | // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}} |
| 64 | // expected-note@-4{{did you mean 'to_global'}} |
| 65 | // expected-note@13{{'to_global' declared here}} |
| 66 | #else |
| 67 | // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}} |
| 68 | #endif |
| 69 | |
| 70 | priv = to_global(glob); |
| 71 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 72 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}} |
| 73 | #else |
| 74 | // expected-error@-4{{assigning '__global int *' to 'int *' changes address space of pointer}} |
| 75 | // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}} |
| 76 | #endif |
| 77 | |
| 78 | priv = to_private(glob); |
| 79 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 80 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}} |
| 81 | #else |
| 82 | // expected-warning@-4{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}} |
| 83 | #endif |
| 84 | |
| 85 | |
| 86 | priv = to_local(glob); |
| 87 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 88 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}} |
| 89 | #else |
| 90 | // expected-error@-4{{assigning '__local int *' to 'int *' changes address space of pointer}} |
| 91 | // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}} |
| 92 | #endif |
| 93 | |
| 94 | glob = to_global(glob); |
| 95 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 96 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
| 97 | #else |
| 98 | // expected-warning@-4{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}} |
| 99 | #endif |
| 100 | |
| 101 | glob = to_private(glob); |
| 102 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 103 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
| 104 | #else |
| 105 | // expected-error@-4{{assigning 'int *' to '__global int *' changes address space of pointer}} |
| 106 | // expected-warning@-5{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}} |
| 107 | #endif |
| 108 | |
| 109 | glob = to_local(glob); |
| 110 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 111 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} |
| 112 | #else |
| 113 | // expected-error@-4{{assigning '__local int *' to '__global int *' changes address space of pointer}} |
| 114 | // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}} |
| 115 | #endif |
| 116 | |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 117 | global char *glob_c = to_global(loc); |
| 118 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 119 | // expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 120 | #else |
| 121 | // expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}} |
Sven van Haastregt | 1076cc2 | 2018-09-20 10:07:27 +0000 | [diff] [blame] | 122 | // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}} |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 123 | #endif |
| 124 | |
Sven van Haastregt | d1f3002 | 2018-09-27 13:20:29 +0000 | [diff] [blame] | 125 | glob_wrong_ty = to_global(glob); |
| 126 | #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 |
| 127 | // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global float *' from 'int'}} |
| 128 | #else |
| 129 | // expected-warning@-4{{incompatible pointer types assigning to '__global float *' from '__global int *'}} |
| 130 | // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}} |
| 131 | #endif |
| 132 | |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 133 | } |