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