xref: /llvm-project/clang/test/SemaOpenACC/compute-construct-num_workers-clause.cpp (revision 4bbdb018a6cb564783cfb9c65ca82b81c6006bb6)
176600aeeSErich Keane // RUN: %clang_cc1 %s -fopenacc -verify
276600aeeSErich Keane 
376600aeeSErich Keane struct NotConvertible{} NC;
476600aeeSErich Keane struct Incomplete *SomeIncomplete; // #INCOMPLETE
576600aeeSErich Keane enum E{} SomeE;
676600aeeSErich Keane enum class E2{} SomeE2;
776600aeeSErich Keane 
876600aeeSErich Keane struct CorrectConvert {
976600aeeSErich Keane   operator int();
1076600aeeSErich Keane } Convert;
1176600aeeSErich Keane 
1276600aeeSErich Keane struct ExplicitConvertOnly {
1376600aeeSErich Keane   explicit operator int() const; // #EXPL_CONV
1476600aeeSErich Keane } Explicit;
1576600aeeSErich Keane 
1676600aeeSErich Keane struct AmbiguousConvert{
1776600aeeSErich Keane   operator int(); // #AMBIG_INT
1876600aeeSErich Keane   operator short(); // #AMBIG_SHORT
1976600aeeSErich Keane   operator float();
2076600aeeSErich Keane } Ambiguous;
2176600aeeSErich Keane 
2276600aeeSErich Keane void Test() {
2376600aeeSErich Keane #pragma acc parallel num_workers(1)
2476600aeeSErich Keane   while(1);
2576600aeeSErich Keane #pragma acc kernels num_workers(1)
2676600aeeSErich Keane   while(1);
2776600aeeSErich Keane 
2876600aeeSErich Keane   // expected-error@+1{{OpenACC clause 'num_workers' requires expression of integer type ('struct NotConvertible' invalid}}
2976600aeeSErich Keane #pragma acc parallel num_workers(NC)
3076600aeeSErich Keane   while(1);
3176600aeeSErich Keane 
3276600aeeSErich Keane   // expected-error@+2{{OpenACC integer expression has incomplete class type 'struct Incomplete'}}
3376600aeeSErich Keane   // expected-note@#INCOMPLETE{{forward declaration of 'Incomplete'}}
3476600aeeSErich Keane #pragma acc kernels num_workers(*SomeIncomplete)
3576600aeeSErich Keane   while(1);
3676600aeeSErich Keane 
3776600aeeSErich Keane #pragma acc parallel num_workers(SomeE)
3876600aeeSErich Keane   while(1);
3976600aeeSErich Keane 
4076600aeeSErich Keane   // expected-error@+1{{OpenACC clause 'num_workers' requires expression of integer type ('enum E2' invalid}}
4176600aeeSErich Keane #pragma acc kernels num_workers(SomeE2)
4276600aeeSErich Keane   while(1);
4376600aeeSErich Keane 
4476600aeeSErich Keane #pragma acc parallel num_workers(Convert)
4576600aeeSErich Keane   while(1);
4676600aeeSErich Keane 
47*4bbdb018Serichkeane   // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'struct ExplicitConvertOnly' to 'int'}}
4876600aeeSErich Keane   // expected-note@#EXPL_CONV{{conversion to integral type 'int'}}
4976600aeeSErich Keane #pragma acc kernels num_workers(Explicit)
5076600aeeSErich Keane   while(1);
5176600aeeSErich Keane 
5276600aeeSErich Keane   // expected-error@+3{{multiple conversions from expression type 'struct AmbiguousConvert' to an integral type}}
5376600aeeSErich Keane   // expected-note@#AMBIG_INT{{conversion to integral type 'int'}}
5476600aeeSErich Keane   // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}}
5576600aeeSErich Keane #pragma acc parallel num_workers(Ambiguous)
5676600aeeSErich Keane   while(1);
5776600aeeSErich Keane }
5876600aeeSErich Keane 
5976600aeeSErich Keane struct HasInt {
6076600aeeSErich Keane   using IntTy = int;
6176600aeeSErich Keane   using ShortTy = short;
6276600aeeSErich Keane   static constexpr int value = 1;
6376600aeeSErich Keane   static constexpr AmbiguousConvert ACValue;
6476600aeeSErich Keane   static constexpr ExplicitConvertOnly EXValue;
6576600aeeSErich Keane 
6676600aeeSErich Keane   operator char();
6776600aeeSErich Keane };
6876600aeeSErich Keane 
6976600aeeSErich Keane template<typename T>
7076600aeeSErich Keane void TestInst() {
7176600aeeSErich Keane 
7276600aeeSErich Keane   // expected-error@+1{{no member named 'Invalid' in 'HasInt'}}
7376600aeeSErich Keane #pragma acc parallel num_workers(HasInt::Invalid)
7476600aeeSErich Keane   while (1);
7576600aeeSErich Keane 
7676600aeeSErich Keane   // expected-error@+2{{no member named 'Invalid' in 'HasInt'}}
7776600aeeSErich Keane   // expected-note@#INST{{in instantiation of function template specialization 'TestInst<HasInt>' requested here}}
7876600aeeSErich Keane #pragma acc kernels num_workers(T::Invalid)
7976600aeeSErich Keane   while (1);
8076600aeeSErich Keane 
8176600aeeSErich Keane   // expected-error@+3{{multiple conversions from expression type 'const AmbiguousConvert' to an integral type}}
8276600aeeSErich Keane   // expected-note@#AMBIG_INT{{conversion to integral type 'int'}}
8376600aeeSErich Keane   // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}}
8476600aeeSErich Keane #pragma acc parallel num_workers(HasInt::ACValue)
8576600aeeSErich Keane   while (1);
8676600aeeSErich Keane 
8776600aeeSErich Keane   // expected-error@+3{{multiple conversions from expression type 'const AmbiguousConvert' to an integral type}}
8876600aeeSErich Keane   // expected-note@#AMBIG_INT{{conversion to integral type 'int'}}
8976600aeeSErich Keane   // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}}
9076600aeeSErich Keane #pragma acc kernels num_workers(T::ACValue)
9176600aeeSErich Keane   while (1);
9276600aeeSErich Keane 
93*4bbdb018Serichkeane   // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'const ExplicitConvertOnly' to 'int'}}
9476600aeeSErich Keane   // expected-note@#EXPL_CONV{{conversion to integral type 'int'}}
9576600aeeSErich Keane #pragma acc parallel num_workers(HasInt::EXValue)
9676600aeeSErich Keane   while (1);
9776600aeeSErich Keane 
98*4bbdb018Serichkeane   // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'const ExplicitConvertOnly' to 'int'}}
9976600aeeSErich Keane   // expected-note@#EXPL_CONV{{conversion to integral type 'int'}}
10076600aeeSErich Keane #pragma acc kernels num_workers(T::EXValue)
10176600aeeSErich Keane   while (1);
10276600aeeSErich Keane 
10376600aeeSErich Keane #pragma acc parallel num_workers(HasInt::value)
10476600aeeSErich Keane   while (1);
10576600aeeSErich Keane 
10676600aeeSErich Keane #pragma acc kernels num_workers(T::value)
10776600aeeSErich Keane   while (1);
10876600aeeSErich Keane 
10976600aeeSErich Keane #pragma acc parallel num_workers(HasInt::IntTy{})
11076600aeeSErich Keane   while (1);
11176600aeeSErich Keane 
11276600aeeSErich Keane #pragma acc kernels num_workers(typename T::ShortTy{})
11376600aeeSErich Keane   while (1);
11476600aeeSErich Keane 
11576600aeeSErich Keane #pragma acc parallel num_workers(HasInt::IntTy{})
11676600aeeSErich Keane   while (1);
11776600aeeSErich Keane 
11876600aeeSErich Keane #pragma acc kernels num_workers(typename T::ShortTy{})
11976600aeeSErich Keane   while (1);
12076600aeeSErich Keane 
12176600aeeSErich Keane   HasInt HI{};
12276600aeeSErich Keane   T MyT{};
12376600aeeSErich Keane 
12476600aeeSErich Keane #pragma acc parallel num_workers(HI)
12576600aeeSErich Keane   while (1);
12676600aeeSErich Keane 
12776600aeeSErich Keane #pragma acc kernels num_workers(MyT)
12876600aeeSErich Keane   while (1);
12976600aeeSErich Keane }
13076600aeeSErich Keane 
13176600aeeSErich Keane void Inst() {
13276600aeeSErich Keane   TestInst<HasInt>(); // #INST
13376600aeeSErich Keane }
134