Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp %s
      2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 %s
      3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s
      4 
      5 void foo() {
      6 }
      7 
      8 #if __cplusplus >= 201103L
      9 // expected-note@+2 4 {{declared here}}
     10 #endif
     11 bool foobool(int argc) {
     12   return argc;
     13 }
     14 
     15 struct S1; // expected-note {{declared here}}
     16 
     17 template <class T, typename S, int N, int ST> // expected-note {{declared here}}
     18 T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
     19 #pragma omp target parallel for simd simdlen // expected-error {{expected '(' after 'simdlen'}}
     20   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     21 
     22 #pragma omp target parallel for simd simdlen ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     23   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     24 
     25 #pragma omp target parallel for simd simdlen () // expected-error {{expected expression}}
     26   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     27 
     28 // expected-error@+3 {{expected ')'}} expected-note@+3 {{to match this '('}}
     29 // expected-error@+2 2 {{expression is not an integral constant expression}}
     30 // expected-note@+1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}}
     31 #pragma omp target parallel for simd simdlen (argc
     32   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     33 
     34 // expected-error@+1 {{argument to 'simdlen' clause must be a strictly positive integer value}}
     35 #pragma omp target parallel for simd simdlen (ST // expected-error {{expected ')'}} expected-note {{to match this '('}}
     36   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     37 
     38 #pragma omp target parallel for simd simdlen (1)) // expected-warning {{extra tokens at the end of '#pragma omp target parallel for simd' are ignored}}
     39   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     40 
     41 #pragma omp target parallel for simd simdlen ((ST > 0) ? 1 + ST : 2)
     42   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     43 
     44   // expected-error@+6 2 {{directive '#pragma omp target parallel for simd' cannot contain more than one 'simdlen' clause}}
     45   // expected-error@+5 2 {{argument to 'simdlen' clause must be a strictly positive integer value}}
     46   // expected-error@+4 2 {{expression is not an integral constant expression}}
     47 #if __cplusplus >= 201103L
     48   // expected-note@+2 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
     49 #endif
     50 #pragma omp target parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5)
     51   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     52 
     53 #pragma omp target parallel for simd simdlen (S) // expected-error {{'S' does not refer to a value}}
     54   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     55 
     56 #if __cplusplus <= 199711L
     57   // expected-error@+4 2 {{expression is not an integral constant expression}}
     58 #else
     59   // expected-error@+2 2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
     60 #endif
     61 #pragma omp target parallel for simd simdlen (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
     62   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     63 
     64  #pragma omp target parallel for simd simdlen (4)
     65   for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     66 
     67   #pragma omp target parallel for simd simdlen (N) // expected-error {{argument to 'simdlen' clause must be a strictly positive integer value}}
     68   for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     69 
     70 #pragma omp target parallel for simd simdlen (2), safelen (4) // OK
     71   for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     72 
     73 #pragma omp target parallel for simd simdlen (4), safelen (4) // OK
     74   for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     75 
     76 #pragma omp target parallel for simd simdlen (8), safelen (4) // expected-error{{the value of 'simdlen' parameter must be less than or equal to the value of the 'safelen' parameter}}
     77   for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
     78 
     79   return argc;
     80 }
     81 
     82 int main(int argc, char **argv) {
     83 #pragma omp target parallel for simd simdlen // expected-error {{expected '(' after 'simdlen'}}
     84   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
     85 
     86 #pragma omp target parallel for simd simdlen ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     87   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
     88 
     89 #pragma omp target parallel for simd simdlen () // expected-error {{expected expression}}
     90   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
     91 
     92 #pragma omp target parallel for simd simdlen (4 // expected-error {{expected ')'}} expected-note {{to match this '('}}
     93   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
     94 
     95 #pragma omp target parallel for simd simdlen (2+2)) // expected-warning {{extra tokens at the end of '#pragma omp target parallel for simd' are ignored}}
     96   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
     97 
     98   // expected-error@+4 {{expression is not an integral constant expression}}
     99 #if __cplusplus >= 201103L
    100   // expected-note@+2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
    101 #endif
    102 #pragma omp target parallel for simd simdlen (foobool(1) > 0 ? 1 : 2)
    103   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    104 
    105   // expected-error@+6 {{expression is not an integral constant expression}}
    106 #if __cplusplus >= 201103L
    107   // expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
    108 #endif
    109 // expected-error@+2 2 {{directive '#pragma omp target parallel for simd' cannot contain more than one 'simdlen' clause}}
    110 // expected-error@+1 2 {{argument to 'simdlen' clause must be a strictly positive integer value}}
    111 #pragma omp target parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5)
    112   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    113 
    114 #pragma omp target parallel for simd simdlen (S1) // expected-error {{'S1' does not refer to a value}}
    115   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    116 
    117 #if __cplusplus <= 199711L
    118   // expected-error@+4 {{expression is not an integral constant expression}}
    119 #else
    120   // expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
    121 #endif
    122 #pragma omp target parallel for simd simdlen (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
    123   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    124 
    125 // expected-error@+3 {{statement after '#pragma omp target parallel for simd' must be a for loop}}
    126 // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, -1, -2>' requested here}}
    127 #pragma omp target parallel for simd simdlen(simdlen(tmain<int, char, -1, -2>(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
    128   foo();
    129 
    130 #pragma omp target parallel for simd simdlen (2), safelen (4) // OK
    131   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    132 
    133 #pragma omp target parallel for simd simdlen (4), safelen (4) // OK
    134   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    135 
    136 #pragma omp target parallel for simd simdlen (8), safelen (4) // expected-error{{the value of 'simdlen' parameter must be less than or equal to the value of the 'safelen' parameter}}
    137   for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
    138 
    139   // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 12, 4>' requested here}}
    140   return tmain<int, char, 12, 4>(argc, argv);
    141 }
    142 
    143