xref: /llvm-project/clang/test/SemaOpenACC/compute-construct-create-clause.cpp (revision a15b685c2d868eaf408d05baa50baa3c9f5cc740)
101e91a2dSerichkeane // RUN: %clang_cc1 %s -fopenacc -verify
201e91a2dSerichkeane 
301e91a2dSerichkeane enum SomeE{};
401e91a2dSerichkeane typedef struct IsComplete {
501e91a2dSerichkeane   struct S { int A; } CompositeMember;
601e91a2dSerichkeane   int ScalarMember;
701e91a2dSerichkeane   float ArrayMember[5];
801e91a2dSerichkeane   SomeE EnumMember;
901e91a2dSerichkeane   char *PointerMember;
1001e91a2dSerichkeane } Complete;
1101e91a2dSerichkeane 
uses(int IntParam,char * PointerParam,float ArrayParam[5],Complete CompositeParam,int & IntParamRef)1201e91a2dSerichkeane void uses(int IntParam, char *PointerParam, float ArrayParam[5], Complete CompositeParam, int &IntParamRef) {
1301e91a2dSerichkeane   int LocalInt;
1401e91a2dSerichkeane   char *LocalPointer;
1501e91a2dSerichkeane   float LocalArray[5];
1601e91a2dSerichkeane   // Check Appertainment:
1701e91a2dSerichkeane #pragma acc parallel create(LocalInt)
1801e91a2dSerichkeane   while(1);
1901e91a2dSerichkeane #pragma acc serial create(LocalInt)
2001e91a2dSerichkeane   while(1);
2101e91a2dSerichkeane #pragma acc kernels create(LocalInt)
2201e91a2dSerichkeane   while(1);
2301e91a2dSerichkeane 
2401e91a2dSerichkeane   // Valid cases:
2501e91a2dSerichkeane #pragma acc parallel create(LocalInt, LocalPointer, LocalArray)
2601e91a2dSerichkeane   while(1);
2701e91a2dSerichkeane #pragma acc parallel create(LocalArray[2:1])
2801e91a2dSerichkeane   while(1);
2901e91a2dSerichkeane 
3001e91a2dSerichkeane   Complete LocalComposite2;
3101e91a2dSerichkeane #pragma acc parallel create(LocalComposite2.ScalarMember, LocalComposite2.ScalarMember)
3201e91a2dSerichkeane   while(1);
3301e91a2dSerichkeane 
34*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
3501e91a2dSerichkeane #pragma acc parallel create(1 + IntParam)
3601e91a2dSerichkeane   while(1);
3701e91a2dSerichkeane 
38*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
3901e91a2dSerichkeane #pragma acc parallel create(+IntParam)
4001e91a2dSerichkeane   while(1);
4101e91a2dSerichkeane 
4201e91a2dSerichkeane   // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
4301e91a2dSerichkeane #pragma acc parallel create(PointerParam[2:])
4401e91a2dSerichkeane   while(1);
4501e91a2dSerichkeane 
4601e91a2dSerichkeane   // expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
4701e91a2dSerichkeane #pragma acc parallel create(ArrayParam[2:5])
4801e91a2dSerichkeane   while(1);
4901e91a2dSerichkeane 
5001e91a2dSerichkeane   // expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
51*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
5201e91a2dSerichkeane #pragma acc parallel create((float*)ArrayParam[2:5])
5301e91a2dSerichkeane   while(1);
54*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
5501e91a2dSerichkeane #pragma acc parallel create((float)ArrayParam[2])
5601e91a2dSerichkeane   while(1);
5701e91a2dSerichkeane }
5801e91a2dSerichkeane 
5901e91a2dSerichkeane template<typename T, unsigned I, typename V>
TemplUses(T t,T (& arrayT)[I],V TemplComp)6001e91a2dSerichkeane void TemplUses(T t, T (&arrayT)[I], V TemplComp) {
61*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
6201e91a2dSerichkeane #pragma acc parallel create(+t)
6301e91a2dSerichkeane   while(true);
6401e91a2dSerichkeane 
6501e91a2dSerichkeane   // NTTP's are only valid if it is a reference to something.
66*a15b685cSErich Keane   // expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
6701e91a2dSerichkeane   // expected-note@#TEMPL_USES_INST{{in instantiation of}}
6801e91a2dSerichkeane #pragma acc parallel create(I)
6901e91a2dSerichkeane   while(true);
7001e91a2dSerichkeane 
71*a15b685cSErich Keane   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
7201e91a2dSerichkeane #pragma acc parallel create(t, I)
7301e91a2dSerichkeane   while(true);
7401e91a2dSerichkeane 
7501e91a2dSerichkeane #pragma acc parallel create(arrayT)
7601e91a2dSerichkeane   while(true);
7701e91a2dSerichkeane 
7801e91a2dSerichkeane #pragma acc parallel create(TemplComp)
7901e91a2dSerichkeane   while(true);
8001e91a2dSerichkeane 
8101e91a2dSerichkeane #pragma acc parallel create(TemplComp.PointerMember[5])
8201e91a2dSerichkeane   while(true);
8301e91a2dSerichkeane  int *Pointer;
8401e91a2dSerichkeane #pragma acc parallel create(Pointer[:I])
8501e91a2dSerichkeane   while(true);
8601e91a2dSerichkeane #pragma acc parallel create(Pointer[:t])
8701e91a2dSerichkeane   while(true);
8801e91a2dSerichkeane   // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
8901e91a2dSerichkeane #pragma acc parallel create(Pointer[1:])
9001e91a2dSerichkeane   while(true);
9101e91a2dSerichkeane }
9201e91a2dSerichkeane 
9301e91a2dSerichkeane template<unsigned I, auto &NTTP_REF>
NTTP()9401e91a2dSerichkeane void NTTP() {
9501e91a2dSerichkeane   // NTTP's are only valid if it is a reference to something.
96*a15b685cSErich Keane   // expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
9701e91a2dSerichkeane   // expected-note@#NTTP_INST{{in instantiation of}}
9801e91a2dSerichkeane #pragma acc parallel create(I)
9901e91a2dSerichkeane   while(true);
10001e91a2dSerichkeane 
10101e91a2dSerichkeane #pragma acc parallel create(NTTP_REF)
10201e91a2dSerichkeane   while(true);
10301e91a2dSerichkeane }
10401e91a2dSerichkeane 
Inst()10501e91a2dSerichkeane void Inst() {
10601e91a2dSerichkeane   static constexpr int NTTP_REFed = 1;
10701e91a2dSerichkeane   int i;
10801e91a2dSerichkeane   int Arr[5];
10901e91a2dSerichkeane   Complete C;
11001e91a2dSerichkeane   TemplUses(i, Arr, C); // #TEMPL_USES_INST
11101e91a2dSerichkeane   NTTP<5, NTTP_REFed>(); // #NTTP_INST
11201e91a2dSerichkeane }
113