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 parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
     70   for (int k = 0; k < argc; ++k)
     71     ++k;
     72 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     73   for (int k = 0; k < argc; ++k)
     74     ++k;
     75 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}}
     76   for (int k = 0; k < argc; ++k)
     77     ++k;
     78 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
     79   for (int k = 0; k < argc; ++k)
     80     ++k;
     81 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     82   for (int k = 0; k < argc; ++k)
     83     ++k;
     84 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
     85   for (int k = 0; k < argc; ++k)
     86     ++k;
     87 #pragma omp target parallel for firstprivate(argc)
     88   for (int k = 0; k < argc; ++k)
     89     ++k;
     90 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
     91   for (int k = 0; k < argc; ++k)
     92     ++k;
     93 #pragma omp target parallel for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
     94   for (int k = 0; k < argc; ++k)
     95     ++k;
     96 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
     97   for (int k = 0; k < argc; ++k)
     98     ++k;
     99 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
    100   for (int k = 0; k < argc; ++k)
    101     ++k;
    102 #pragma omp target parallel for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
    103   for (int k = 0; k < argc; ++k)
    104     ++k;
    105 #pragma omp parallel
    106   {
    107     int v = 0;
    108     int i;
    109 #pragma omp target parallel for firstprivate(i)
    110     for (int k = 0; k < argc; ++k) {
    111       i = k;
    112       v += i;
    113     }
    114   }
    115 #pragma omp parallel shared(i)
    116 #pragma omp parallel private(i)
    117 #pragma omp target parallel for firstprivate(j)
    118   for (int k = 0; k < argc; ++k)
    119     ++k;
    120 #pragma omp target parallel for firstprivate(i)
    121   for (int k = 0; k < argc; ++k)
    122     ++k;
    123 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
    124   for (i = 0; i < argc; ++i)
    125     foo();
    126 #pragma omp parallel private(i)
    127 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
    128   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
    129     foo();
    130 #pragma omp parallel reduction(+ : i)
    131 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
    132   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
    133     foo();
    134   return 0;
    135 }
    136 
    137 namespace A {
    138 double x;
    139 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
    140 }
    141 namespace B {
    142 using A::x;
    143 }
    144 
    145 int main(int argc, char **argv) {
    146   const int d = 5;
    147   const int da[5] = {0};
    148   S4 e(4);
    149   S5 g(5);
    150   S3 m;
    151   S6 n(2);
    152   int i;
    153   int &j = i;
    154 #pragma omp target parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
    155   for (i = 0; i < argc; ++i)
    156     foo();
    157 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    158   for (i = 0; i < argc; ++i)
    159     foo();
    160 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}}
    161   for (i = 0; i < argc; ++i)
    162     foo();
    163 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    164   for (i = 0; i < argc; ++i)
    165     foo();
    166 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    167   for (i = 0; i < argc; ++i)
    168     foo();
    169 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    170   for (i = 0; i < argc; ++i)
    171     foo();
    172 #pragma omp target parallel for firstprivate(argc)
    173   for (i = 0; i < argc; ++i)
    174     foo();
    175 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
    176   for (i = 0; i < argc; ++i)
    177     foo();
    178 #pragma omp target parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
    179   for (i = 0; i < argc; ++i)
    180     foo();
    181 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
    182   for (i = 0; i < argc; ++i)
    183     foo();
    184 #pragma omp target parallel for firstprivate(2 * 2) // expected-error {{expected variable name}}
    185   for (i = 0; i < argc; ++i)
    186     foo();
    187 #pragma omp target parallel for firstprivate(ba) // OK
    188   for (i = 0; i < argc; ++i)
    189     foo();
    190 #pragma omp target parallel for firstprivate(ca) // OK
    191   for (i = 0; i < argc; ++i)
    192     foo();
    193 #pragma omp target parallel for firstprivate(da) // OK
    194   for (i = 0; i < argc; ++i)
    195     foo();
    196   int xa;
    197 #pragma omp target parallel for firstprivate(xa) // OK
    198   for (i = 0; i < argc; ++i)
    199     foo();
    200 #pragma omp target parallel for firstprivate(S2::S2s) // OK
    201   for (i = 0; i < argc; ++i)
    202     foo();
    203 #pragma omp target parallel for firstprivate(S2::S2sc) // OK
    204   for (i = 0; i < argc; ++i)
    205     foo();
    206 #pragma omp target parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp target parallel for'}}
    207   for (i = 0; i < argc; ++i)
    208     foo();
    209 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
    210   for (i = 0; i < argc; ++i)
    211     foo();
    212 #pragma omp target parallel for firstprivate(m) // OK
    213   for (i = 0; i < argc; ++i)
    214     foo();
    215 #pragma omp target parallel for firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
    216   for (i = 0; i < argc; ++i)
    217     foo();
    218 #pragma omp target parallel for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
    219   for (i = 0; i < argc; ++i)
    220     foo();
    221 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
    222   for (i = 0; i < argc; ++i)    // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
    223     foo();
    224 #pragma omp parallel shared(xa)
    225 #pragma omp target parallel for firstprivate(xa) // OK: may be firstprivate
    226   for (i = 0; i < argc; ++i)
    227     foo();
    228 #pragma omp target parallel for firstprivate(j)
    229   for (i = 0; i < argc; ++i)
    230     foo();
    231 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
    232   for (i = 0; i < argc; ++i)
    233     foo();
    234 #pragma omp target parallel for lastprivate(n) firstprivate(n) // OK
    235   for (i = 0; i < argc; ++i)
    236     foo();
    237 #pragma omp parallel
    238   {
    239     int v = 0;
    240     int i;
    241 #pragma omp target parallel for firstprivate(i)
    242     for (int k = 0; k < argc; ++k) {
    243       i = k;
    244       v += i;
    245     }
    246   }
    247 #pragma omp parallel private(i)
    248 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
    249   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
    250     foo();
    251 #pragma omp parallel reduction(+ : i)
    252 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
    253   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
    254     foo();
    255   static int si;
    256 #pragma omp target parallel for firstprivate(si) // OK
    257   for (i = 0; i < argc; ++i)
    258     si = i + 1;
    259 
    260   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
    261 }
    262