Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp %s
      2 
      3 void foo() {
      4 }
      5 
      6 bool foobool(int argc) {
      7   return argc;
      8 }
      9 
     10 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
     11 extern S1 a;
     12 class S2 {
     13   mutable int a;
     14 
     15 public:
     16   S2() : a(0) {}
     17   S2(const S2 &s2) : a(s2.a) {}
     18   static float S2s;
     19   static const float S2sc;
     20 };
     21 const float S2::S2sc = 0;
     22 const S2 b;
     23 const S2 ba[5];
     24 class S3 {
     25   int a;
     26   S3 &operator=(const S3 &s3);
     27 
     28 public:
     29   S3() : a(0) {}
     30   S3(const S3 &s3) : a(s3.a) {}
     31 };
     32 const S3 c;
     33 const S3 ca[5];
     34 extern const int f;
     35 class S4 {
     36   int a;
     37   S4();
     38   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
     39 
     40 public:
     41   S4(int v) : a(v) {}
     42 };
     43 class S5 {
     44   int a;
     45   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
     46 
     47 public:
     48   S5() : a(0) {}
     49   S5(int v) : a(v) {}
     50 };
     51 class S6 {
     52   int a;
     53   S6() : a(0) {}
     54 
     55 public:
     56   S6(const S6 &s6) : a(s6.a) {}
     57   S6(int v) : a(v) {}
     58 };
     59 
     60 S3 h;
     61 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
     62 
     63 template <class I, class C>
     64 int foomain(int argc, char **argv) {
     65   I e(4);
     66   C g(5);
     67   int i;
     68   int &j = i;
     69 #pragma omp target
     70 #pragma omp teams
     71 #pragma omp distribute parallel for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
     72   for (int k = 0; k < argc; ++k)
     73     ++k;
     74 #pragma omp target
     75 #pragma omp teams
     76 #pragma omp distribute parallel for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     77   for (int k = 0; k < argc; ++k)
     78     ++k;
     79 #pragma omp target
     80 #pragma omp teams
     81 #pragma omp distribute parallel for simd firstprivate() // expected-error {{expected expression}}
     82   for (int k = 0; k < argc; ++k)
     83     ++k;
     84 #pragma omp target
     85 #pragma omp teams
     86 #pragma omp distribute parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
     87   for (int k = 0; k < argc; ++k)
     88     ++k;
     89 #pragma omp target
     90 #pragma omp teams
     91 #pragma omp distribute parallel for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     92   for (int k = 0; k < argc; ++k)
     93     ++k;
     94 #pragma omp target
     95 #pragma omp teams
     96 #pragma omp distribute parallel for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
     97   for (int k = 0; k < argc; ++k)
     98     ++k;
     99 #pragma omp target
    100 #pragma omp teams
    101 #pragma omp distribute parallel for simd firstprivate(argc)
    102   for (int k = 0; k < argc; ++k)
    103     ++k;
    104 #pragma omp target
    105 #pragma omp teams
    106 #pragma omp distribute parallel for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
    107   for (int k = 0; k < argc; ++k)
    108     ++k;
    109 #pragma omp target
    110 #pragma omp teams
    111 #pragma omp distribute parallel for simd firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
    112   for (int k = 0; k < argc; ++k)
    113     ++k;
    114 #pragma omp target
    115 #pragma omp teams
    116 #pragma omp distribute parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
    117   for (int k = 0; k < argc; ++k)
    118     ++k;
    119 #pragma omp target
    120 #pragma omp teams
    121 #pragma omp distribute parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
    122   for (int k = 0; k < argc; ++k)
    123     ++k;
    124 #pragma omp target
    125 #pragma omp teams
    126 #pragma omp distribute parallel for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
    127   for (int k = 0; k < argc; ++k)
    128     ++k;
    129 #pragma omp parallel
    130   {
    131     int v = 0;
    132     int i;
    133 #pragma omp target
    134 #pragma omp teams
    135 #pragma omp distribute parallel for simd firstprivate(i)
    136     for (int k = 0; k < argc; ++k) {
    137       i = k;
    138       v += i;
    139     }
    140   }
    141 #pragma omp parallel shared(i)
    142 #pragma omp parallel private(i)
    143 #pragma omp target
    144 #pragma omp teams
    145 #pragma omp distribute parallel for simd firstprivate(j)
    146   for (int k = 0; k < argc; ++k)
    147     ++k;
    148 #pragma omp target
    149 #pragma omp teams
    150 #pragma omp distribute parallel for simd firstprivate(i)
    151   for (int k = 0; k < argc; ++k)
    152     ++k;
    153 #pragma omp target
    154 #pragma omp teams
    155 #pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
    156   for (i = 0; i < argc; ++i)
    157     foo();
    158 #pragma omp parallel private(i)
    159 #pragma omp target
    160 #pragma omp teams
    161 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
    162   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
    163     foo();
    164 #pragma omp parallel reduction(+ : i)
    165 #pragma omp target
    166 #pragma omp teams
    167 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
    168   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
    169     foo();
    170   return 0;
    171 }
    172 
    173 namespace A {
    174 double x;
    175 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
    176 }
    177 namespace B {
    178 using A::x;
    179 }
    180 
    181 int main(int argc, char **argv) {
    182   const int d = 5;
    183   const int da[5] = {0};
    184   S4 e(4);
    185   S5 g(5);
    186   S3 m;
    187   S6 n(2);
    188   int i;
    189   int &j = i;
    190 #pragma omp target
    191 #pragma omp teams
    192 #pragma omp distribute parallel for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
    193   for (i = 0; i < argc; ++i)
    194     foo();
    195 #pragma omp target
    196 #pragma omp teams
    197 #pragma omp distribute parallel for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    198   for (i = 0; i < argc; ++i)
    199     foo();
    200 #pragma omp target
    201 #pragma omp teams
    202 #pragma omp distribute parallel for simd firstprivate() // expected-error {{expected expression}}
    203   for (i = 0; i < argc; ++i)
    204     foo();
    205 #pragma omp target
    206 #pragma omp teams
    207 #pragma omp distribute parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    208   for (i = 0; i < argc; ++i)
    209     foo();
    210 #pragma omp target
    211 #pragma omp teams
    212 #pragma omp distribute parallel for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    213   for (i = 0; i < argc; ++i)
    214     foo();
    215 #pragma omp target
    216 #pragma omp teams
    217 #pragma omp distribute parallel for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    218   for (i = 0; i < argc; ++i)
    219     foo();
    220 #pragma omp target
    221 #pragma omp teams
    222 #pragma omp distribute parallel for simd firstprivate(argc)
    223   for (i = 0; i < argc; ++i)
    224     foo();
    225 #pragma omp target
    226 #pragma omp teams
    227 #pragma omp distribute parallel for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
    228   for (i = 0; i < argc; ++i)
    229     foo();
    230 #pragma omp target
    231 #pragma omp teams
    232 #pragma omp distribute parallel for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
    233   for (i = 0; i < argc; ++i)
    234     foo();
    235 #pragma omp target
    236 #pragma omp teams
    237 #pragma omp distribute parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
    238   for (i = 0; i < argc; ++i)
    239     foo();
    240 #pragma omp target
    241 #pragma omp teams
    242 #pragma omp distribute parallel for simd firstprivate(2 * 2) // expected-error {{expected variable name}}
    243   for (i = 0; i < argc; ++i)
    244     foo();
    245 #pragma omp target
    246 #pragma omp teams
    247 #pragma omp distribute parallel for simd firstprivate(ba) // OK
    248   for (i = 0; i < argc; ++i)
    249     foo();
    250 #pragma omp target
    251 #pragma omp teams
    252 #pragma omp distribute parallel for simd firstprivate(ca) // OK
    253   for (i = 0; i < argc; ++i)
    254     foo();
    255 #pragma omp target
    256 #pragma omp teams
    257 #pragma omp distribute parallel for simd firstprivate(da) // OK
    258   for (i = 0; i < argc; ++i)
    259     foo();
    260   int xa;
    261 #pragma omp target
    262 #pragma omp teams
    263 #pragma omp distribute parallel for simd firstprivate(xa) // OK
    264   for (i = 0; i < argc; ++i)
    265     foo();
    266 #pragma omp target
    267 #pragma omp teams
    268 #pragma omp distribute parallel for simd firstprivate(S2::S2s) // OK
    269   for (i = 0; i < argc; ++i)
    270     foo();
    271 #pragma omp target
    272 #pragma omp teams
    273 #pragma omp distribute parallel for simd firstprivate(S2::S2sc) // OK
    274   for (i = 0; i < argc; ++i)
    275     foo();
    276 #pragma omp target
    277 #pragma omp teams
    278 #pragma omp distribute parallel for simd safelen(5) // OK
    279   for (i = 0; i < argc; ++i)
    280     foo();
    281 #pragma omp target
    282 #pragma omp teams
    283 #pragma omp distribute parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
    284   for (i = 0; i < argc; ++i)
    285     foo();
    286 #pragma omp target
    287 #pragma omp teams
    288 #pragma omp distribute parallel for simd firstprivate(m) // OK
    289   for (i = 0; i < argc; ++i)
    290     foo();
    291 #pragma omp target
    292 #pragma omp teams
    293 #pragma omp distribute parallel for simd firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
    294   for (i = 0; i < argc; ++i)
    295     foo();
    296 #pragma omp target
    297 #pragma omp teams
    298 #pragma omp distribute parallel for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
    299   for (i = 0; i < argc; ++i)
    300     foo();
    301 #pragma omp target
    302 #pragma omp teams
    303 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
    304   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
    305     foo();
    306 #pragma omp parallel shared(xa)
    307 #pragma omp target
    308 #pragma omp teams
    309 #pragma omp distribute parallel for simd firstprivate(xa) // OK: may be firstprivate
    310   for (i = 0; i < argc; ++i)
    311     foo();
    312 #pragma omp target
    313 #pragma omp teams
    314 #pragma omp distribute parallel for simd firstprivate(j)
    315   for (i = 0; i < argc; ++i)
    316     foo();
    317 #pragma omp target
    318 #pragma omp teams
    319 #pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
    320   for (i = 0; i < argc; ++i)
    321     foo();
    322 #pragma omp target
    323 #pragma omp teams
    324 #pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // OK
    325   for (i = 0; i < argc; ++i)
    326     foo();
    327 #pragma omp parallel
    328   {
    329     int v = 0;
    330     int i;
    331 #pragma omp target
    332 #pragma omp teams
    333 #pragma omp distribute parallel for simd firstprivate(i)
    334     for (int k = 0; k < argc; ++k) {
    335       i = k;
    336       v += i;
    337     }
    338   }
    339 #pragma omp parallel private(i)
    340 #pragma omp target
    341 #pragma omp teams
    342 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
    343   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
    344     foo();
    345 #pragma omp parallel reduction(+ : i)
    346 #pragma omp target
    347 #pragma omp teams
    348 #pragma omp distribute parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
    349   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
    350     foo();
    351   static int si;
    352 #pragma omp target
    353 #pragma omp teams
    354 #pragma omp distribute parallel for simd firstprivate(si) // OK
    355   for (i = 0; i < argc; ++i)
    356     si = i + 1;
    357 
    358   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
    359 }
    360