xref: /llvm-project/clang/test/SemaOpenACC/compute-construct-if-clause.c (revision bfc2dbe02e00f0023c0a2d58b53cdbd1f4139f02)
1daa88364SErich Keane // RUN: %clang_cc1 %s -fopenacc -verify
2daa88364SErich Keane 
3daa88364SErich Keane void BoolExpr(int *I, float *F) {
4daa88364SErich Keane 
5daa88364SErich Keane   typedef struct {} SomeStruct;
6daa88364SErich Keane   int Array[5];
7daa88364SErich Keane 
8daa88364SErich Keane   struct C{};
9daa88364SErich Keane   // expected-error@+1{{expected expression}}
10daa88364SErich Keane #pragma acc parallel if (struct C f())
11daa88364SErich Keane   while(0);
12daa88364SErich Keane 
13daa88364SErich Keane   // expected-error@+1{{unexpected type name 'SomeStruct': expected expression}}
14daa88364SErich Keane #pragma acc serial if (SomeStruct)
15daa88364SErich Keane   while(0);
16daa88364SErich Keane 
17daa88364SErich Keane   // expected-error@+1{{unexpected type name 'SomeStruct': expected expression}}
18daa88364SErich Keane #pragma acc serial if (SomeStruct())
19daa88364SErich Keane   while(0);
20daa88364SErich Keane 
21daa88364SErich Keane   SomeStruct S;
22daa88364SErich Keane   // expected-error@+1{{statement requires expression of scalar type ('SomeStruct' invalid)}}
23daa88364SErich Keane #pragma acc serial if (S)
24daa88364SErich Keane   while(0);
25daa88364SErich Keane 
26daa88364SErich Keane   // expected-warning@+1{{address of array 'Array' will always evaluate to 'true'}}
27daa88364SErich Keane #pragma acc kernels if (Array)
28daa88364SErich Keane   while(0);
29daa88364SErich Keane 
30daa88364SErich Keane   // expected-warning@+4{{incompatible pointer types assigning to 'int *' from 'float *'}}
31daa88364SErich Keane   // expected-warning@+3{{using the result of an assignment as a condition without parentheses}}
32daa88364SErich Keane   // expected-note@+2{{place parentheses around the assignment to silence this warning}}
33daa88364SErich Keane   // expected-note@+1{{use '==' to turn this assignment into an equality comparison}}
34daa88364SErich Keane #pragma acc kernels if (I = F)
35daa88364SErich Keane   while(0);
36daa88364SErich Keane 
37daa88364SErich Keane #pragma acc parallel if (I)
38daa88364SErich Keane   while(0);
39daa88364SErich Keane 
40daa88364SErich Keane #pragma acc serial if (F)
41daa88364SErich Keane   while(0);
42daa88364SErich Keane 
43daa88364SErich Keane #pragma acc kernels if (*I < *F)
44daa88364SErich Keane   while(0);
45daa88364SErich Keane 
46*bfc2dbe0Serichkeane   // expected-error@+1{{OpenACC 'data' construct must have at least one 'copy', 'copyin', 'copyout', 'create', 'no_create', 'present', 'deviceptr', 'attach' or 'default' clause}}
47daa88364SErich Keane #pragma acc data if (*I < *F)
48daa88364SErich Keane   while(0);
49daa88364SErich Keane #pragma acc parallel loop if (*I < *F)
50e4d57d6aSerichkeane   for(int i = 0; i < 5; ++i);
51daa88364SErich Keane #pragma acc serial loop if (*I < *F)
52e4d57d6aSerichkeane   for(int i = 0; i < 5; ++i);
53daa88364SErich Keane #pragma acc kernels loop if (*I < *F)
54e4d57d6aSerichkeane   for(int i = 0; i < 5; ++i);
556119340eSerichkeane 
5642f4e505SErich Keane   // expected-error@+1{{OpenACC 'if' clause is not valid on 'loop' directive}}
576119340eSerichkeane #pragma acc loop if(I)
58b0cfbfd7SErich Keane   for(int i = 5; i < 10;++i);
59daa88364SErich Keane }
60