1 // RUN: %clang_cc1 -verify=expected,omp4 -fopenmp -fopenmp-version=45 %s -Wno-openmp-mapping -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,omp5 -fopenmp -fopenmp-version=50 %s -Wno-openmp-mapping -Wuninitialized
3 
4 // RUN: %clang_cc1 -verify=expected,omp4 -fopenmp-simd -fopenmp-version=45 %s -Wno-openmp-mapping -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,omp5 -fopenmp-simd -fopenmp-version=50 %s -Wno-openmp-mapping -Wuninitialized
6 
7 extern int omp_default_mem_alloc;
foo()8 void foo() {
9 }
10 
foobool(int argc)11 bool foobool(int argc) {
12   return argc;
13 }
14 
xxx(int argc)15 void xxx(int argc) {
16   int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
17 #pragma omp target
18 #pragma omp teams distribute simd firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
19   for (int i = 0; i < 10; ++i)
20     ;
21 }
22 
23 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
24 extern S1 a;
25 class S2 {
26   mutable int a;
27 
28 public:
S2()29   S2() : a(0) {}
S2(const S2 & s2)30   S2(const S2 &s2) : a(s2.a) {}
31   static float S2s;
32   static const float S2sc;
33 };
34 const float S2::S2sc = 0;
35 const S2 b;
36 const S2 ba[5];
37 class S3 {
38   int a;
39   S3 &operator=(const S3 &s3);
40 
41 public:
S3()42   S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
S3(S3 & s3)43   S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}
44 };
45 const S3 c;
46 const S3 ca[5];
47 extern const int f;
48 class S4 {
49   int a;
50   S4();
51   S4(const S4 &s4);
52 public:
S4(int v)53   S4(int v):a(v) { }
54 };
55 class S5 {
56   int a;
S5()57   S5():a(0) {}
S5(const S5 & s5)58   S5(const S5 &s5):a(s5.a) { }
59 public:
S5(int v)60   S5(int v):a(v) { }
61 };
62 class S6 {
63   int a;
64 public:
S6()65   S6() : a(0) { }
66 };
67 
68 S3 h;
69 #pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}
70 
main(int argc,char ** argv)71 int main(int argc, char **argv) {
72   const int d = 5;
73   const int da[5] = { 0 };
74   S4 e(4);
75   S5 g(5);
76   S6 p;
77   int i, k;
78   int &j = i;
79 
80 #pragma omp target
81 #pragma omp teams distribute simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
82   for (i = 0; i < argc; ++i) foo();
83 
84 #pragma omp target
85 #pragma omp teams distribute simd firstprivate ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
86   for (i = 0; i < argc; ++i) foo();
87 
88 #pragma omp target
89 #pragma omp teams distribute simd firstprivate () // expected-error {{expected expression}}
90   for (i = 0; i < argc; ++i) foo();
91 
92 #pragma omp target
93 #pragma omp teams distribute simd firstprivate (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
94   for (i = 0; i < argc; ++i) foo();
95 
96 #pragma omp target
97 #pragma omp teams distribute simd firstprivate (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
98   for (i = 0; i < argc; ++i) foo();
99 
100 #pragma omp target
101 #pragma omp teams distribute simd firstprivate (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
102   for (i = 0; i < argc; ++i) foo();
103 
104 #pragma omp target
105 #pragma omp teams distribute simd firstprivate (argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
106   for (i = 0; i < argc; ++i) foo();
107 
108 #pragma omp target
109 #pragma omp teams distribute simd firstprivate (S1) // expected-error {{'S1' does not refer to a value}}
110   for (i = 0; i < argc; ++i) foo();
111 
112 #pragma omp target
113 #pragma omp teams distribute simd firstprivate (k, a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-error {{no matching constructor for initialization of 'S3'}}
114   for (i = 0; i < argc; ++i) foo();
115 
116 #pragma omp target
117 #pragma omp teams distribute simd firstprivate (argv[1]) // expected-error {{expected variable name}}
118   for (i = 0; i < argc; ++i) foo();
119 
120 #pragma omp target
121 #pragma omp teams distribute simd firstprivate(ba)
122   for (i = 0; i < argc; ++i) foo();
123 
124 #pragma omp target
125 #pragma omp teams distribute simd firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}
126   for (i = 0; i < argc; ++i) foo();
127 
128 #pragma omp target
129 #pragma omp teams distribute simd firstprivate(da)
130   for (i = 0; i < argc; ++i) foo();
131 
132 #pragma omp target
133 #pragma omp teams distribute simd firstprivate(S2::S2s)
134   for (i = 0; i < argc; ++i) foo();
135 
136 #pragma omp target
137 #pragma omp teams distribute simd firstprivate(S2::S2sc)
138   for (i = 0; i < argc; ++i) foo();
139 
140 #pragma omp target
141 #pragma omp teams distribute simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
142   for (i = 0; i < argc; ++i) foo();
143 
144 #pragma omp target
145 #pragma omp teams distribute simd private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} omp4-note 2 {{defined as private}} omp5-note {{defined as private}}
146   for (i = 0; i < argc; ++i) foo(); // omp4-error {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be private, predetermined as linear}}
147 
148 #pragma omp target
149 #pragma omp teams distribute simd firstprivate(i)
150   for (j = 0; j < argc; ++j) foo();
151 
152 #pragma omp target
153 #pragma omp teams distribute simd firstprivate(i) // expected-note {{defined as firstprivate}}
154   for (i = 0; i < argc; ++i) foo(); // expected-error {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be firstprivate, predetermined as linear}}
155 
156 #pragma omp target
157 #pragma omp teams distribute simd firstprivate(j)
158   for (i = 0; i < argc; ++i) foo();
159 
160 // expected-error@+2 {{lastprivate variable cannot be firstprivate}} expected-note@+2 {{defined as lastprivate}}
161 #pragma omp target
162 #pragma omp teams distribute simd lastprivate(argc), firstprivate(argc) // OK
163   for (i = 0; i < argc; ++i) foo();
164 
165   return 0;
166 }
167