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 };
     18 const S2 b;
     19 const S2 ba[5];
     20 class S3 {
     21   int a;
     22 
     23 public:
     24   S3() : a(0) {}
     25 };
     26 const S3 ca[5];
     27 class S4 {
     28   int a;
     29   S4(); // expected-note {{implicitly declared private here}}
     30 
     31 public:
     32   S4(int v) : a(v) {
     33 #pragma omp taskloop simd private(a) private(this->a)
     34     for (int k = 0; k < v; ++k)
     35       ++this->a;
     36   }
     37 };
     38 class S5 {
     39   int a;
     40   S5() : a(0) {} // expected-note {{implicitly declared private here}}
     41 
     42 public:
     43   S5(int v) : a(v) {}
     44   S5 &operator=(S5 &s) {
     45 #pragma omp taskloop simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
     46     for (int k = 0; k < s.a; ++k)
     47       ++s.a;
     48     return *this;
     49   }
     50 };
     51 
     52 template <typename T>
     53 class S6 {
     54 public:
     55   T a;
     56 
     57   S6() : a(0) {}
     58   S6(T v) : a(v) {
     59 #pragma omp taskloop simd private(a) private(this->a)
     60     for (int k = 0; k < v; ++k)
     61       ++this->a;
     62   }
     63   S6 &operator=(S6 &s) {
     64 #pragma omp taskloop simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
     65     for (int k = 0; k < s.a; ++k)
     66       ++s.a;
     67     return *this;
     68   }
     69 };
     70 
     71 template <typename T>
     72 class S7 : public T {
     73   T a;
     74   S7() : a(0) {}
     75 
     76 public:
     77   S7(T v) : a(v) {
     78 #pragma omp taskloop simd private(a) private(this->a) private(T::a)
     79     for (int k = 0; k < a.a; ++k)
     80       ++this->a.a;
     81   }
     82   S7 &operator=(S7 &s) {
     83 #pragma omp taskloop simd private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
     84     for (int k = 0; k < s.a.a; ++k)
     85       ++s.a.a;
     86     return *this;
     87   }
     88 };
     89 
     90 S3 h;
     91 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
     92 
     93 template <class I, class C>
     94 int foomain(I argc, C **argv) {
     95   I e(4);
     96   I g(5);
     97   int i;
     98   int &j = i;
     99 #pragma omp taskloop simd private // expected-error {{expected '(' after 'private'}}
    100   for (int k = 0; k < argc; ++k)
    101     ++k;
    102 #pragma omp taskloop simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    103   for (int k = 0; k < argc; ++k)
    104     ++k;
    105 #pragma omp taskloop simd private() // expected-error {{expected expression}}
    106   for (int k = 0; k < argc; ++k)
    107     ++k;
    108 #pragma omp taskloop simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    109   for (int k = 0; k < argc; ++k)
    110     ++k;
    111 #pragma omp taskloop simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    112   for (int k = 0; k < argc; ++k)
    113     ++k;
    114 #pragma omp taskloop simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    115   for (int k = 0; k < argc; ++k)
    116     ++k;
    117 #pragma omp taskloop simd private(argc)
    118   for (int k = 0; k < argc; ++k)
    119     ++k;
    120 #pragma omp taskloop simd private(S1) // expected-error {{'S1' does not refer to a value}}
    121   for (int k = 0; k < argc; ++k)
    122     ++k;
    123 #pragma omp taskloop simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
    124   for (int k = 0; k < argc; ++k)
    125     ++k;
    126 #pragma omp taskloop simd private(argv[1]) // expected-error {{expected variable name}}
    127   for (int k = 0; k < argc; ++k)
    128     ++k;
    129 #pragma omp taskloop simd private(e, g)
    130   for (int k = 0; k < argc; ++k)
    131     ++k;
    132 #pragma omp taskloop simd private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
    133   for (int k = 0; k < argc; ++k)
    134     ++k;
    135 #pragma omp taskloop simd shared(i)
    136   for (int k = 0; k < argc; ++k)
    137     ++k;
    138 #pragma omp parallel
    139   {
    140     int v = 0;
    141     int i;
    142 #pragma omp taskloop simd private(i)
    143     for (int k = 0; k < argc; ++k) {
    144       i = k;
    145       v += i;
    146     }
    147   }
    148 #pragma omp parallel shared(i)
    149 #pragma omp parallel private(i)
    150 #pragma omp taskloop simd private(j)
    151   for (int k = 0; k < argc; ++k)
    152     ++k;
    153 #pragma omp taskloop simd private(i)
    154   for (int k = 0; k < argc; ++k)
    155     ++k;
    156   return 0;
    157 }
    158 
    159 void bar(S4 a[2]) {
    160 #pragma omp parallel
    161 #pragma omp taskloop simd private(a)
    162   for (int i = 0; i < 2; ++i)
    163     foo();
    164 }
    165 
    166 namespace A {
    167 double x;
    168 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
    169 }
    170 namespace B {
    171 using A::x;
    172 }
    173 
    174 int main(int argc, char **argv) {
    175   S4 e(4);
    176   S5 g(5);
    177   S6<float> s6(0.0) , s6_0(1.0);
    178   S7<S6<float> > s7(0.0) , s7_0(1.0);
    179   int i;
    180   int &j = i;
    181 #pragma omp taskloop simd private // expected-error {{expected '(' after 'private'}}
    182   for (int k = 0; k < argc; ++k)
    183     ++k;
    184 #pragma omp taskloop simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    185   for (int k = 0; k < argc; ++k)
    186     ++k;
    187 #pragma omp taskloop simd private() // expected-error {{expected expression}}
    188   for (int k = 0; k < argc; ++k)
    189     ++k;
    190 #pragma omp taskloop simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    191   for (int k = 0; k < argc; ++k)
    192     ++k;
    193 #pragma omp taskloop simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    194   for (int k = 0; k < argc; ++k)
    195     ++k;
    196 #pragma omp taskloop simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    197   for (int k = 0; k < argc; ++k)
    198     ++k;
    199 #pragma omp taskloop simd private(argc)
    200   for (int k = 0; k < argc; ++k)
    201     ++k;
    202 #pragma omp taskloop simd private(S1) // expected-error {{'S1' does not refer to a value}}
    203   for (int k = 0; k < argc; ++k)
    204     ++k;
    205 #pragma omp taskloop simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
    206   for (int k = 0; k < argc; ++k)
    207     ++k;
    208 #pragma omp taskloop simd private(argv[1]) // expected-error {{expected variable name}}
    209   for (int k = 0; k < argc; ++k)
    210     ++k;
    211 #pragma omp taskloop simd private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
    212   for (int k = 0; k < argc; ++k)
    213     ++k;
    214 #pragma omp taskloop simd private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
    215   for (int k = 0; k < argc; ++k)
    216     ++k;
    217 #pragma omp taskloop simd private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
    218   for (int k = 0; k < argc; ++k)
    219     ++k;
    220 #pragma omp taskloop simd shared(i)
    221   for (int k = 0; k < argc; ++k)
    222     ++k;
    223 #pragma omp parallel
    224   {
    225     int i;
    226 #pragma omp taskloop simd private(i)
    227     for (int k = 0; k < argc; ++k)
    228       ++k;
    229   }
    230 #pragma omp parallel shared(i)
    231 #pragma omp parallel private(i)
    232 #pragma omp taskloop simd private(j)
    233   for (int k = 0; k < argc; ++k)
    234     ++k;
    235 #pragma omp taskloop simd private(i)
    236   for (int k = 0; k < argc; ++k)
    237     ++k;
    238   static int si;
    239 #pragma omp taskloop simd private(si) // OK
    240   for(int k = 0; k < argc; ++k)
    241     si = k + 1;
    242 
    243   s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
    244   s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
    245   return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
    246 }
    247 
    248