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