xref: /llvm-project/clang/test/SemaOpenACC/compute-construct-deviceptr-clause.cpp (revision 48c8a5791ae71c96661479f684459b7b9427a22d)
1 // RUN: %clang_cc1 %s -fopenacc -verify
2 
3 struct S {
4   int IntMem;
5   int *PtrMem;
6   operator int*();
7 };
8 
uses()9 void uses() {
10   int LocalInt;
11   int *LocalPtr;
12   int Array[5];
13   int *PtrArray[5];
14   struct S s;
15 
16   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
17 #pragma acc parallel deviceptr(LocalInt)
18   while (true);
19 
20 #pragma acc parallel deviceptr(LocalPtr)
21   while (true);
22 
23   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int[5]'}}
24 #pragma acc parallel deviceptr(Array)
25   while (true);
26 
27   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
28 #pragma acc parallel deviceptr(Array[0])
29   while (true);
30 
31   // expected-error@+2{{OpenACC sub-array is not allowed here}}
32   // expected-note@+1{{expected variable of pointer type}}
33 #pragma acc parallel deviceptr(Array[0:1])
34   while (true);
35 
36   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int *[5]'}}
37 #pragma acc parallel deviceptr(PtrArray)
38   while (true);
39 
40 #pragma acc parallel deviceptr(PtrArray[0])
41   while (true);
42 
43   // expected-error@+2{{OpenACC sub-array is not allowed here}}
44   // expected-note@+1{{expected variable of pointer type}}
45 #pragma acc parallel deviceptr(PtrArray[0:1])
46   while (true);
47 
48   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'struct S'}}
49 #pragma acc parallel deviceptr(s)
50   while (true);
51 
52   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
53 #pragma acc parallel deviceptr(s.IntMem)
54   while (true);
55 
56 #pragma acc parallel deviceptr(s.PtrMem)
57   while (true);
58 }
59 
60 template<typename T, typename TPtr, typename TStruct, auto &R1>
Templ()61 void Templ() {
62   T SomeInt;
63   TPtr SomePtr;
64   T SomeIntArray[5];
65   TPtr SomeIntPtrArray[5];
66   TStruct SomeStruct;
67 
68   // expected-error@+2{{expected pointer in 'deviceptr' clause, type is 'int'}}
69   // expected-note@#INST{{in instantiation of function template specialization}}
70 #pragma acc parallel deviceptr(SomeInt)
71   while (true);
72 
73 #pragma acc parallel deviceptr(SomePtr)
74   while (true);
75 
76   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int[5]'}}
77 #pragma acc parallel deviceptr(SomeIntArray)
78   while (true);
79 
80   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
81 #pragma acc parallel deviceptr(SomeIntArray[0])
82   while (true);
83 
84   // expected-error@+2{{OpenACC sub-array is not allowed here}}
85   // expected-note@+1{{expected variable of pointer type}}
86 #pragma acc parallel deviceptr(SomeIntArray[0:1])
87   while (true);
88 
89   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int *[5]'}}
90 #pragma acc parallel deviceptr(SomeIntPtrArray)
91   while (true);
92 
93 #pragma acc parallel deviceptr(SomeIntPtrArray[0])
94   while (true);
95 
96   // expected-error@+2{{OpenACC sub-array is not allowed here}}
97   // expected-note@+1{{expected variable of pointer type}}
98 #pragma acc parallel deviceptr(SomeIntPtrArray[0:1])
99   while (true);
100 
101   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'S'}}
102 #pragma acc parallel deviceptr(SomeStruct)
103   while (true);
104 
105   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
106 #pragma acc parallel deviceptr(SomeStruct.IntMem)
107   while (true);
108 
109 #pragma acc parallel deviceptr(SomeStruct.PtrMem)
110   while (true);
111 
112   // expected-error@+1{{expected pointer in 'deviceptr' clause, type is 'int'}}
113 #pragma acc parallel deviceptr(R1)
114   while (true);
115 }
116 
inst()117 void inst() {
118   static constexpr int CEVar = 1;
119   Templ<int, int*, S, CEVar>(); // #INST
120 }
121