Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s
      2 
      3 void foo();
      4 
      5 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}}
      6 #pragma omp sections
      7 
      8 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}}
      9 #pragma omp sections foo
     10 
     11 void test_no_clause() {
     12   int i;
     13 #pragma omp sections
     14   {
     15     foo();
     16   }
     17 
     18 // expected-error@+2 {{the statement for '#pragma omp sections' must be a compound statement}}
     19 #pragma omp sections
     20   ++i;
     21 
     22 #pragma omp sections
     23   {
     24     foo();
     25     foo(); // expected-error {{statement in 'omp sections' directive must be enclosed into a section region}}
     26   }
     27 
     28 }
     29 
     30 void test_branch_protected_scope() {
     31   int i = 0;
     32 L1:
     33   ++i;
     34 
     35   int x[24];
     36 
     37 #pragma omp parallel
     38 #pragma omp sections
     39   {
     40     if (i == 5)
     41       goto L1; // expected-error {{use of undeclared label 'L1'}}
     42     else if (i == 6)
     43       return; // expected-error {{cannot return from OpenMP region}}
     44     else if (i == 7)
     45       goto L2;
     46     else if (i == 8) {
     47     L2:
     48       x[i]++;
     49     }
     50 #pragma omp section
     51     if (i == 5)
     52       goto L1; // expected-error {{use of undeclared label 'L1'}}
     53     else if (i == 6)
     54       return; // expected-error {{cannot return from OpenMP region}}
     55     else if (i == 7)
     56       goto L3;
     57     else if (i == 8) {
     58     L3:
     59       x[i]++;
     60     }
     61   }
     62 
     63   if (x[0] == 0)
     64     goto L2; // expected-error {{use of undeclared label 'L2'}}
     65   else if (x[1] == 1)
     66     goto L1;
     67   goto L3; // expected-error {{use of undeclared label 'L3'}}
     68 }
     69 
     70 void test_invalid_clause() {
     71   int i;
     72 #pragma omp parallel
     73 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
     74 #pragma omp sections foo bar
     75   {
     76     foo();
     77 // expected-error@+1 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp section'}}
     78 #pragma omp section nowait
     79     ;
     80   }
     81 }
     82 
     83 void test_non_identifiers() {
     84   int i, x;
     85 
     86 #pragma omp parallel
     87 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
     88 #pragma omp sections;
     89   {
     90     foo();
     91   }
     92 #pragma omp parallel
     93 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
     94 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
     95 #pragma omp sections linear(x);
     96   {
     97     foo();
     98   }
     99 
    100 #pragma omp parallel
    101 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
    102 #pragma omp sections private(x);
    103   {
    104     foo();
    105   }
    106 
    107 #pragma omp parallel
    108 // expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
    109 #pragma omp sections, private(x);
    110   {
    111     foo();
    112   }
    113 }
    114 
    115 void test_private() {
    116   int i;
    117 #pragma omp parallel
    118 // expected-error@+2 {{expected expression}}
    119 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
    120 #pragma omp sections private(
    121   {
    122     foo();
    123   }
    124 #pragma omp parallel
    125 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
    126 // expected-error@+1 2 {{expected expression}}
    127 #pragma omp sections private(,
    128   {
    129     foo();
    130   }
    131 #pragma omp parallel
    132 // expected-error@+1 2 {{expected expression}}
    133 #pragma omp sections private(, )
    134   {
    135     foo();
    136   }
    137 #pragma omp parallel
    138 // expected-error@+1 {{expected expression}}
    139 #pragma omp sections private()
    140   {
    141     foo();
    142   }
    143 #pragma omp parallel
    144 // expected-error@+1 {{expected expression}}
    145 #pragma omp sections private(int)
    146   {
    147     foo();
    148   }
    149 #pragma omp parallel
    150 // expected-error@+1 {{expected variable name}}
    151 #pragma omp sections private(0)
    152   {
    153     foo();
    154   }
    155 
    156   int x, y, z;
    157 #pragma omp parallel
    158 #pragma omp sections private(x)
    159   {
    160     foo();
    161   }
    162 #pragma omp parallel
    163 #pragma omp sections private(x, y)
    164   {
    165     foo();
    166   }
    167 #pragma omp parallel
    168 #pragma omp sections private(x, y, z)
    169   {
    170     foo();
    171   }
    172 }
    173 
    174 void test_lastprivate() {
    175   int i;
    176 #pragma omp parallel
    177 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
    178 // expected-error@+1 {{expected expression}}
    179 #pragma omp sections lastprivate(
    180   {
    181     foo();
    182   }
    183 
    184 #pragma omp parallel
    185 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
    186 // expected-error@+1 2 {{expected expression}}
    187 #pragma omp sections lastprivate(,
    188   {
    189     foo();
    190   }
    191 #pragma omp parallel
    192 // expected-error@+1 2 {{expected expression}}
    193 #pragma omp sections lastprivate(, )
    194   {
    195     foo();
    196   }
    197 #pragma omp parallel
    198 // expected-error@+1 {{expected expression}}
    199 #pragma omp sections lastprivate()
    200   {
    201     foo();
    202   }
    203 #pragma omp parallel
    204 // expected-error@+1 {{expected expression}}
    205 #pragma omp sections lastprivate(int)
    206   {
    207     foo();
    208   }
    209 #pragma omp parallel
    210 // expected-error@+1 {{expected variable name}}
    211 #pragma omp sections lastprivate(0)
    212   {
    213     foo();
    214   }
    215 
    216   int x, y, z;
    217 #pragma omp parallel
    218 #pragma omp sections lastprivate(x)
    219   {
    220     foo();
    221   }
    222 #pragma omp parallel
    223 #pragma omp sections lastprivate(x, y)
    224   {
    225     foo();
    226   }
    227 #pragma omp parallel
    228 #pragma omp sections lastprivate(x, y, z)
    229   {
    230     foo();
    231   }
    232 }
    233 
    234 void test_firstprivate() {
    235   int i;
    236 #pragma omp parallel
    237 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
    238 // expected-error@+1 {{expected expression}}
    239 #pragma omp sections firstprivate(
    240   {
    241     foo();
    242   }
    243 
    244 #pragma omp parallel
    245 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
    246 // expected-error@+1 2 {{expected expression}}
    247 #pragma omp sections firstprivate(,
    248   {
    249     foo();
    250   }
    251 #pragma omp parallel
    252 // expected-error@+1 2 {{expected expression}}
    253 #pragma omp sections firstprivate(, )
    254   {
    255     foo();
    256   }
    257 #pragma omp parallel
    258 // expected-error@+1 {{expected expression}}
    259 #pragma omp sections firstprivate()
    260   {
    261     foo();
    262   }
    263 #pragma omp parallel
    264 // expected-error@+1 {{expected expression}}
    265 #pragma omp sections firstprivate(int)
    266   {
    267     foo();
    268   }
    269 #pragma omp parallel
    270 // expected-error@+1 {{expected variable name}}
    271 #pragma omp sections firstprivate(0)
    272   {
    273     foo();
    274   }
    275 
    276   int x, y, z;
    277 #pragma omp parallel
    278 #pragma omp sections lastprivate(x) firstprivate(x)
    279   {
    280     foo();
    281   }
    282 #pragma omp parallel
    283 #pragma omp sections lastprivate(x, y) firstprivate(x, y)
    284   {
    285     foo();
    286   }
    287 #pragma omp parallel
    288 #pragma omp sections lastprivate(x, y, z) firstprivate(x, y, z)
    289   {
    290     foo();
    291   }
    292 }
    293 
    294