brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.3 KiB · deab634 Raw
390 lines · cpp
1// RUN: %clang_cc1 %s -fopenacc -verify2 3constexpr int three() { return 3; }4constexpr int one() { return 1; }5constexpr int neg() { return -1; }6constexpr int zero() { return 0; }7 8struct NotConstexpr {9  constexpr NotConstexpr(){};10 11  operator int(){ return 1; }12};13struct ConvertsNegative {14  constexpr ConvertsNegative(){};15 16  constexpr operator int(){ return -1; }17};18struct ConvertsOne{19  constexpr ConvertsOne(){};20 21  constexpr operator int(){ return 1; }22};23 24struct ConvertsThree{25  constexpr ConvertsThree(){};26 27  constexpr operator int(){ return 3; }28};29 30template<typename T, int Val>31void negative_zero_constexpr_templ() {32  // expected-error@+1 2{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}33#pragma acc serial loop tile(*, T{})34  for(int i = 0; i < 5; ++i)35    for(int j = 0; j < 5; ++j);36 37  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}38#pragma acc parallel loop tile(Val, *)39  for(int i = 0; i < 5; ++i)40    for(int j = 0; j < 5; ++j);41 42  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}43#pragma acc kernels loop tile(zero(), *)44  for(int i = 0; i < 5; ++i)45    for(int j = 0; j < 5; ++j);46}47 48void negative_zero_constexpr() {49  negative_zero_constexpr_templ<int, 1>(); // expected-note{{in instantiation of function template specialization}}50  negative_zero_constexpr_templ<int, -1>(); // expected-note{{in instantiation of function template specialization}}51 52  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}53#pragma acc serial loop tile(0, *)54  for(int i = 0; i < 5; ++i)55    for(int j = 0; j < 5; ++j);56 57  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}58#pragma acc parallel loop tile(1, 0)59  for(int i = 0; i < 5; ++i)60    for(int j = 0; j < 5; ++j);61 62  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}63#pragma acc kernels loop tile(1, -1)64  for(int i = 0; i < 5; ++i)65    for(int j = 0; j < 5; ++j);66 67  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}68#pragma acc parallel loop tile(-1, 0)69  for(int i = 0; i < 5; ++i)70    for(int j = 0; j < 5; ++j);71 72  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}73#pragma acc serial loop tile(zero(), 0)74  for(int i = 0; i < 5; ++i)75    for(int j = 0; j < 5; ++j);76 77  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}78#pragma acc kernels loop tile(1, neg())79  for(int i = 0; i < 5; ++i)80    for(int j = 0; j < 5; ++j);81 82  // expected-error@+1{{OpenACC 'tile' clause size expression must be an asterisk or a constant expression}}83#pragma acc parallel loop tile(NotConstexpr{})84  for(int i = 0; i < 5; ++i);85 86  // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}87#pragma acc serial loop tile(1, ConvertsNegative{})88  for(int i = 0; i < 5; ++i)89    for(int j = 0; j < 5; ++j);90 91#pragma acc kernels loop tile(*, ConvertsOne{})92  for(int i = 0; i < 5; ++i)93    for(int j = 0; j < 5; ++j);94}95 96template<unsigned One>97void only_for_loops_templ() {98  // expected-note@+1{{'parallel loop' construct is here}}99#pragma acc parallel loop tile(One)100  // expected-error@+1{{OpenACC 'parallel loop' construct can only be applied to a 'for' loop}}101  while(true);102 103  // expected-note@+1{{'serial loop' construct is here}}104#pragma acc serial loop tile(One)105  // expected-error@+1{{OpenACC 'serial loop' construct can only be applied to a 'for' loop}}106  do {} while(true);107 108  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}109#pragma acc kernels loop tile(One, 2) // expected-note 2{{active 'tile' clause defined here}}110  for(int i = 0; i < 5; ++i)111      // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}112    while(true);113 114  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}115#pragma acc serial loop tile(One, 2) // expected-note 2{{active 'tile' clause defined here}}116  for(int i = 0; i < 5; ++i)117      // expected-error@+1{{do loop cannot appear in intervening code of a 'serial loop' with a 'tile' clause}}118    do{}while(true);119}120 121 122void only_for_loops() {123  // expected-note@+1{{'parallel loop' construct is here}}124#pragma acc parallel loop tile(1)125  // expected-error@+1{{OpenACC 'parallel loop' construct can only be applied to a 'for' loop}}126  while(true);127 128  // expected-note@+1{{'serial loop' construct is here}}129#pragma acc serial loop tile(1)130  // expected-error@+1{{OpenACC 'serial loop' construct can only be applied to a 'for' loop}}131  do {} while(true);132 133  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}134#pragma acc kernels loop tile(1, 2) // expected-note 2{{active 'tile' clause defined here}}135  for(int i = 0; i < 5; ++i)136      // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}137    while(true);138 139  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}140#pragma acc parallel loop tile(1, 2) // expected-note 2{{active 'tile' clause defined here}}141  for(int i = 0; i < 5; ++i)142      // expected-error@+1{{do loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}143    do{}while(true);144}145 146template<unsigned Val>147void depth_too_high_templ() {148  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}149#pragma acc kernels loop tile (Val, *, Val) // expected-note{{active 'tile' clause defined here}}150  for(int i = 0; i < 5; ++i)151    for(int j = 0; j < 5; ++j);152 153  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}154#pragma acc parallel loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}155  for(int i = 0; i < 5; ++i)156    for(int j = 0; j < 5; ++j)157      // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}158      while(true);159 160  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}161#pragma acc serial loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}162  for(int i = 0; i < 5; ++i)163    for(int j = 0; j < 5; ++j)164      // expected-error@+1{{do loop cannot appear in intervening code of a 'serial loop' with a 'tile' clause}}165      do{}while(true);166 167  int Arr[Val+5];168 169  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}170#pragma acc kernels loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}171  for(int i = 0; i < 5; ++i)172    for(auto x : Arr)173      // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}174      while(true)175        for(int j = 0; j < 5; ++j);176 177#pragma acc parallel loop tile (Val, *, Val)178  for(int i = 0; i < 5; ++i)179    for(auto x : Arr)180      for(int j = 0; j < 5; ++j)181        while(true);182}183 184void depth_too_high() {185  depth_too_high_templ<3>();186 187int Arr[5];188 189  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}190#pragma acc serial loop tile (1, *, 3) // expected-note{{active 'tile' clause defined here}}191  for(int i = 0; i < 5; ++i)192    for(int j = 0; j < 5; ++j);193 194  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}195#pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}196  for(int i = 0; i < 5; ++i)197    for(int j = 0; j < 5; ++j)198      // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}199      while(true);200 201  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}202#pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}203  for(int i = 0; i < 5; ++i)204    for(int j = 0; j < 5; ++j)205      // expected-error@+1{{do loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}206      do{}while(true);207 208  // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}209#pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}210  for(int i = 0; i < 5; ++i)211    for(int j = 0; j < 5; ++j)212      // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}213      while(true)214        for(int j = 0; j < 5; ++j);215 216#pragma acc parallel loop tile (1, *, 3)217  for(int i = 0; i < 5; ++i)218    for(auto x : Arr)219      for(int j = 0; j < 5; ++j)220        while(true);221}222 223template<unsigned Val>224void not_single_loop_templ() {225 226  int Arr[Val];227 228#pragma acc parallel loop tile (Val, *, 3) // expected-note{{active 'tile' clause defined here}}229  for(int i = 0; i < 5; ++i) {230    for (auto x : Arr)231      for(int k = 0; k < 5; ++k);232  // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'parallel loop' construct with a 'tile' clause}}233    for(int j = 0; j < 5; ++j)234      for(int k = 0; k < 5; ++k);235  }236}237 238void not_single_loop() {239  not_single_loop_templ<3>(); // no diagnostic, was diagnosed in phase 1.240 241  int Arr[5];242 243#pragma acc parallel loop tile (1, *, 3)// expected-note{{active 'tile' clause defined here}}244  for(int i = 0; i < 5; ++i) {245    for (auto x : Arr)246      for(int k = 0; k < 5; ++k);247  // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'parallel loop' construct with a 'tile' clause}}248    for(int j = 0; j < 5; ++j)249      for(int k = 0; k < 5; ++k);250  }251}252 253template<unsigned Val>254void no_other_directives_templ() {255 256  int Arr[Val];257 258#pragma acc parallel loop tile (Val, *, 3) // expected-note{{active 'tile' clause defined here}}259  for(int i = 0; i < 5; ++i) {260    for (auto x : Arr) {261  // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}262#pragma acc serial263      ;264      for(int j = 0; j < 5; ++j);265    }266  }267 268  // OK, in innermost269#pragma acc parallel loop tile (Val, *, 3)270  for(int i = 0; i < 5; ++i) {271    for(int j = 0; j < 5; ++j) {272      for (auto x : Arr) {273#pragma acc serial274      ;275      }276    }277  }278}279 280void no_other_directives() {281  no_other_directives_templ<3>();282  int Arr[5];283 284#pragma acc parallel loop tile (1, *, 3) // expected-note{{active 'tile' clause defined here}}285  for(int i = 0; i < 5; ++i) {286    for (auto x : Arr) {287  // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}288#pragma acc serial289      ;290      for(int j = 0; j < 5; ++j);291    }292  }293 294  // OK, in innermost295#pragma acc parallel loop tile (3, *, 3)296  for(int i = 0; i < 5; ++i) {297    for(int j = 0; j < 5; ++j) {298      for (auto x : Arr) {299#pragma acc serial300      ;301      }302    }303  }304}305 306void call();307template<unsigned Val>308void intervening_templ() {309#pragma acc parallel loop tile(1, Val, *) // expected-note{{active 'tile' clause defined here}}310  for(int i = 0; i < 5; ++i) {311    //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}312    call();313    for(int j = 0; j < 5; ++j)314      for(int k = 0; k < 5; ++k);315  }316 317#pragma acc parallel loop tile(1, Val, *) // expected-note{{active 'tile' clause defined here}}318  for(int i = 0; i < 5; ++i) {319    //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}320    unsigned I;321    for(int j = 0; j < 5; ++j)322      for(int k = 0; k < 5; ++k);323  }324 325#pragma acc parallel loop tile(1, Val, *)326  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}327  // expected-note@-2{{'parallel loop' construct is here}}328  for(int i = 0;;++i) {329  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}330  // expected-note@-5{{'parallel loop' construct is here}}331    for(int j = 0;;++j)332  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}333  // expected-note@-8{{'parallel loop' construct is here}}334      for(int k = 0;;++k)335        call();336  }337}338 339void intervening() {340  intervening_templ<3>();341 342#pragma acc parallel loop tile(1, 2, *) // expected-note{{active 'tile' clause defined here}}343  for(int i = 0; i < 5; ++i) {344    //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}345    call();346    for(int j = 0; j < 5; ++j)347      for(int k = 0; k < 5; ++k);348  }349 350#pragma acc parallel loop tile(1, 2, *) // expected-note{{active 'tile' clause defined here}}351  for(int i = 0; i < 5; ++i) {352    //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}353    unsigned I;354    for(int j = 0; j < 5; ++j)355      for(int k = 0; k < 5; ++k);356  }357 358#pragma acc parallel loop tile(1, 2, *)359  for(int i = 0; i < 5; ++i) {360    for(int j = 0; j < 5; ++j)361      for(int k = 0; k < 5; ++k)362        call();363  }364 365#pragma acc parallel loop tile(1, 2, *)366  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}367  // expected-note@-2{{'parallel loop' construct is here}}368  for(int i = 0;;++i) {369  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}370  // expected-note@-5{{'parallel loop' construct is here}}371    for(int j = 0;;++j)372  // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}373  // expected-note@-8{{'parallel loop' construct is here}}374      for(int k = 0;;++k)375        for(;;)376        call();377  }378}379 380void collapse_tile_depth() {381  // expected-error@+4{{'collapse' clause specifies a loop count greater than the number of available loops}}382  // expected-note@+3{{active 'collapse' clause defined here}}383  // expected-error@+2{{'tile' clause specifies a loop count greater than the number of available loops}}384  // expected-note@+1{{active 'tile' clause defined here}}385#pragma acc parallel loop tile(1, 2, 3) collapse (3)386  for(int i = 0; i < 5;++i) {387    for(int j = 0; j < 5; ++j);388  }389}390