Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
      2 
      3 namespace X {
      4   int x;
      5 };
      6 
      7 struct B {
      8   static int ib; // expected-note {{'B::ib' declared here}}
      9   static int bfoo() { return 8; }
     10 };
     11 
     12 int bfoo() { return 4; }
     13 
     14 int z;
     15 const int C1 = 1;
     16 const int C2 = 2;
     17 void test_linear_colons()
     18 {
     19   int B = 0;
     20   #pragma omp simd linear(B:bfoo())
     21   for (int i = 0; i < 10; ++i) ;
     22   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
     23   #pragma omp simd linear(B::ib:B:bfoo())
     24   for (int i = 0; i < 10; ++i) ;
     25   // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
     26   #pragma omp simd linear(B:ib)
     27   for (int i = 0; i < 10; ++i) ;
     28   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
     29   #pragma omp simd linear(z:B:ib)
     30   for (int i = 0; i < 10; ++i) ;
     31   #pragma omp simd linear(B:B::bfoo())
     32   for (int i = 0; i < 10; ++i) ;
     33   #pragma omp simd linear(X::x : ::z)
     34   for (int i = 0; i < 10; ++i) ;
     35   #pragma omp simd linear(B,::z, X::x)
     36   for (int i = 0; i < 10; ++i) ;
     37   #pragma omp simd linear(::z)
     38   for (int i = 0; i < 10; ++i) ;
     39   // expected-error@+1 {{expected variable name}}
     40   #pragma omp simd linear(B::bfoo())
     41   for (int i = 0; i < 10; ++i) ;
     42   #pragma omp simd linear(B::ib,B:C1+C2)
     43   for (int i = 0; i < 10; ++i) ;
     44 }
     45 
     46 template<int L, class T, class N> T test_template(T* arr, N num) {
     47   N i;
     48   T sum = (T)0;
     49   T ind2 = - num * L; // expected-note {{'ind2' defined here}}
     50   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
     51 #pragma omp simd linear(ind2:L)
     52   for (i = 0; i < num; ++i) {
     53     T cur = arr[(int)ind2];
     54     ind2 += L;
     55     sum += cur;
     56   }
     57   return T();
     58 }
     59 
     60 template<int LEN> int test_warn() {
     61   int ind2 = 0;
     62   // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
     63   #pragma omp simd linear(ind2:LEN)
     64   for (int i = 0; i < 100; i++) {
     65     ind2 += LEN;
     66   }
     67   return ind2;
     68 }
     69 
     70 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
     71 extern S1 a;
     72 class S2 {
     73   mutable int a;
     74 public:
     75   S2():a(0) { }
     76 };
     77 const S2 b; // expected-note 2 {{'b' defined here}}
     78 const S2 ba[5];
     79 class S3 {
     80   int a;
     81 public:
     82   S3():a(0) { }
     83 };
     84 const S3 ca[5];
     85 class S4 {
     86   int a;
     87   S4();
     88 public:
     89   S4(int v):a(v) { }
     90 };
     91 class S5 {
     92   int a;
     93   S5():a(0) {}
     94 public:
     95   S5(int v):a(v) { }
     96 };
     97 
     98 S3 h;
     99 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
    100 
    101 template<class I, class C> int foomain(I argc, C **argv) {
    102   I e(4);
    103   I g(5);
    104   int i;
    105   int &j = i; // expected-note {{'j' defined here}}
    106   #pragma omp simd linear // expected-error {{expected '(' after 'linear'}}
    107   for (int k = 0; k < argc; ++k) ++k;
    108   #pragma omp simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    109   for (int k = 0; k < argc; ++k) ++k;
    110   #pragma omp simd linear () // expected-error {{expected expression}}
    111   for (int k = 0; k < argc; ++k) ++k;
    112   #pragma omp simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    113   for (int k = 0; k < argc; ++k) ++k;
    114   #pragma omp simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    115   for (int k = 0; k < argc; ++k) ++k;
    116   #pragma omp simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    117   for (int k = 0; k < argc; ++k) ++k;
    118   #pragma omp simd linear (argc : 5)
    119   for (int k = 0; k < argc; ++k) ++k;
    120   #pragma omp simd linear (S1) // expected-error {{'S1' does not refer to a value}}
    121   for (int k = 0; k < argc; ++k) ++k;
    122   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
    123   // expected-error@+1 {{const-qualified variable cannot be linear}}
    124   #pragma omp simd linear (a, b:B::ib)
    125   for (int k = 0; k < argc; ++k) ++k;
    126   #pragma omp simd linear (argv[1]) // expected-error {{expected variable name}}
    127   for (int k = 0; k < argc; ++k) ++k;
    128   #pragma omp simd linear(e, g)
    129   for (int k = 0; k < argc; ++k) ++k;
    130   #pragma omp simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
    131   for (int k = 0; k < argc; ++k) ++k;
    132   #pragma omp simd linear(i)
    133   for (int k = 0; k < argc; ++k) ++k;
    134   #pragma omp parallel
    135   {
    136     int v = 0;
    137     int i;
    138     #pragma omp simd linear(v:i)
    139     for (int k = 0; k < argc; ++k) { i = k; v += i; }
    140   }
    141   #pragma omp simd linear(j) // expected-error {{arguments of OpenMP clause 'linear' cannot be of reference type}}
    142   for (int k = 0; k < argc; ++k) ++k;
    143   int v = 0;
    144   #pragma omp simd linear(v:j)
    145   for (int k = 0; k < argc; ++k) { ++k; v += j; }
    146   #pragma omp simd linear(i)
    147   for (int k = 0; k < argc; ++k) ++k;
    148   return 0;
    149 }
    150 
    151 int main(int argc, char **argv) {
    152   double darr[100];
    153   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
    154   test_template<-4>(darr, 4);
    155   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
    156   test_warn<0>();
    157 
    158   S4 e(4); // expected-note {{'e' defined here}}
    159   S5 g(5); // expected-note {{'g' defined here}}
    160   int i;
    161   int &j = i; // expected-note {{'j' defined here}}
    162   #pragma omp simd linear // expected-error {{expected '(' after 'linear'}}
    163   for (int k = 0; k < argc; ++k) ++k;
    164   #pragma omp simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    165   for (int k = 0; k < argc; ++k) ++k;
    166   #pragma omp simd linear () // expected-error {{expected expression}}
    167   for (int k = 0; k < argc; ++k) ++k;
    168   #pragma omp simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
    169   for (int k = 0; k < argc; ++k) ++k;
    170   #pragma omp simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
    171   for (int k = 0; k < argc; ++k) ++k;
    172   #pragma omp simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
    173   for (int k = 0; k < argc; ++k) ++k;
    174   #pragma omp simd linear (argc)
    175   for (int k = 0; k < argc; ++k) ++k;
    176   #pragma omp simd linear (S1) // expected-error {{'S1' does not refer to a value}}
    177   for (int k = 0; k < argc; ++k) ++k;
    178   // expected-error@+2 {{linear variable with incomplete type 'S1'}}
    179   // expected-error@+1 {{const-qualified variable cannot be linear}}
    180   #pragma omp simd linear (a, b)
    181   for (int k = 0; k < argc; ++k) ++k;
    182   #pragma omp simd linear (argv[1]) // expected-error {{expected variable name}}
    183   for (int k = 0; k < argc; ++k) ++k;
    184   // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
    185   // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
    186   #pragma omp simd linear(e, g)
    187   for (int k = 0; k < argc; ++k) ++k;
    188   #pragma omp simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
    189   for (int k = 0; k < argc; ++k) ++k;
    190   #pragma omp parallel
    191   {
    192     int i;
    193     #pragma omp simd linear(i)
    194     for (int k = 0; k < argc; ++k) ++k;
    195     #pragma omp simd linear(i : 4)
    196     for (int k = 0; k < argc; ++k) { ++k; i += 4; }
    197   }
    198   #pragma omp simd linear(j) // expected-error {{arguments of OpenMP clause 'linear' cannot be of reference type 'int &'}}
    199   for (int k = 0; k < argc; ++k) ++k;
    200   #pragma omp simd linear(i)
    201   for (int k = 0; k < argc; ++k) ++k;
    202 
    203   foomain<int,char>(argc,argv);
    204   return 0;
    205 }
    206 
    207