xref: /llvm-project/clang/test/SemaOpenACC/parallel-loc-and-stmt.c (revision 5901d4005f015a46185ddc080038c1a3db3fa2c7)
1 // RUN: %clang_cc1 %s -verify -fopenacc
2 
3 // expected-error@+1{{OpenACC construct 'parallel' cannot be used here; it can only be used in a statement context}}
4 #pragma acc parallel
5 
6 // expected-error@+1{{OpenACC construct 'serial' cannot be used here; it can only be used in a statement context}}
7 #pragma acc serial
8 
9 // expected-error@+1{{OpenACC construct 'kernels' cannot be used here; it can only be used in a statement context}}
10 #pragma acc kernels
11 
12 // expected-error@+1{{OpenACC construct 'parallel' cannot be used here; it can only be used in a statement context}}
13 #pragma acc parallel
14 int foo;
15 // expected-error@+1{{OpenACC construct 'serial' cannot be used here; it can only be used in a statement context}}
16 #pragma acc serial
17 int foo2;
18 // expected-error@+1{{OpenACC construct 'kernels' cannot be used here; it can only be used in a statement context}}
19 #pragma acc kernels
20 int foo3;
21 
22 struct S {
23 // expected-error@+1{{OpenACC construct 'parallel' cannot be used here; it can only be used in a statement context}}
24 #pragma acc parallel
25 int foo;
26 // expected-error@+1{{OpenACC construct 'serial' cannot be used here; it can only be used in a statement context}}
27 #pragma acc serial
28 int foo2;
29 // expected-error@+1{{OpenACC construct 'kernels' cannot be used here; it can only be used in a statement context}}
30 #pragma acc kernels
31 int foo3;
32 };
33 
func()34 void func() {
35   // FIXME: Should we disallow this on declarations, or consider this to be on
36   // the initialization? This is currently rejected in C because
37   // Parser::ParseOpenACCDirectiveStmt() calls ParseStatement() and passes the
38   // statement context as "SubStmt" which does not allow for a declaration in C.
39 #pragma acc parallel
40   int foo; // expected-error {{expected expression}}
41 
42 #pragma acc parallel
43   {
44 #pragma acc parallel
45     {
46     }
47   }
48 
49   {
50 // expected-error@+2{{expected statement}}
51 #pragma acc parallel
52   }
53 
54   {
55 // expected-error@+2{{expected statement}}
56 #pragma acc serial
57   }
58   {
59 // expected-error@+2{{expected statement}}
60 #pragma acc kernels
61   }
62 
63 #pragma acc parallel
64   while(0){}
65 
66 #pragma acc parallel
67   for(;;){}
68 
69 #pragma acc parallel
70 #pragma acc parallel
71   for(;;){}
72 
73 // expected-error@+2{{expected statement}}
74 #pragma acc parallel
75 };
76