Skip to content

Commit 73763be

Browse files
committed
Dealias clauses correctly, which should eliminate failures after tablegen. Also, sort the clause kind list so that diagnostics are alphabetical
1 parent e4eddde commit 73763be

File tree

2 files changed

+105
-87
lines changed

2 files changed

+105
-87
lines changed

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 80 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -202,131 +202,132 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Out,
202202
return printOpenACCAtomicKind(Out, AK);
203203
}
204204

205-
/// Represents the kind of an OpenACC clause.
205+
/// Represents the kind of an OpenACC clause. Sorted alphabetically, since this
206+
/// order ends up influencing the sorting of the list diagnostic.
206207
enum class OpenACCClauseKind : uint8_t {
207-
/// 'finalize' clause, allowed on 'exit data' directive.
208-
Finalize,
209-
/// 'if_present' clause, allowed on 'host_data' and 'update' directives.
210-
IfPresent,
211-
/// 'seq' clause, allowed on 'loop' and 'routine' directives.
212-
Seq,
213-
/// 'independent' clause, allowed on 'loop' directives.
214-
Independent,
208+
/// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined
209+
/// constructs.
210+
Async,
211+
/// 'attach' clause, allowed on Compute and Combined constructs, plus 'data'
212+
/// and 'enter data'.
213+
Attach,
215214
/// 'auto' clause, allowed on 'loop' directives.
216215
Auto,
217-
/// 'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
218-
Worker,
219-
/// 'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
220-
Vector,
221-
/// 'nohost' clause, allowed on 'routine' directives.
222-
NoHost,
223-
/// 'default' clause, allowed on parallel, serial, kernel (and compound)
224-
/// constructs.
225-
Default,
226-
/// 'if' clause, allowed on all the Compute Constructs, Data Constructs,
227-
/// Executable Constructs, and Combined Constructs.
228-
If,
229-
/// 'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
230-
Self,
216+
/// 'bind' clause, allowed on routine constructs.
217+
Bind,
218+
/// 'collapse' clause, allowed on 'loop' and Combined constructs.
219+
Collapse,
231220
/// 'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and
232221
/// 'declare'.
233222
Copy,
234223
/// 'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.
235224
PCopy,
236225
/// 'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.
237226
PresentOrCopy,
238-
/// 'use_device' clause, allowed on 'host_data' construct.
239-
UseDevice,
240-
/// 'attach' clause, allowed on Compute and Combined constructs, plus 'data'
241-
/// and 'enter data'.
242-
Attach,
227+
/// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data',
228+
/// 'enter data', and 'declare'.
229+
CopyIn,
230+
/// 'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
231+
PCopyIn,
232+
/// 'copyin' clause alias 'present_or_copyin'. Preserved for diagnostic
233+
/// purposes.
234+
PresentOrCopyIn,
235+
/// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data',
236+
/// 'exit data', and 'declare'.
237+
CopyOut,
238+
/// 'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
239+
PCopyOut,
240+
/// 'copyout' clause alias 'present_or_copyout'. Preserved for diagnostic
241+
/// purposes.
242+
PresentOrCopyOut,
243+
/// 'create' clause, allowed on Compute and Combined constructs, plus 'data',
244+
/// 'enter data', and 'declare'.
245+
Create,
246+
/// 'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
247+
PCreate,
248+
/// 'create' clause alias 'present_or_create'. Preserved for diagnostic
249+
/// purposes.
250+
PresentOrCreate,
251+
/// 'default' clause, allowed on parallel, serial, kernel (and compound)
252+
/// constructs.
253+
Default,
254+
/// 'default_async' clause, allowed on 'set' construct.
255+
DefaultAsync,
243256
/// 'delete' clause, allowed on the 'exit data' construct.
244257
Delete,
245258
/// 'detach' clause, allowed on the 'exit data' construct.
246259
Detach,
247260
/// 'device' clause, allowed on the 'update' construct.
248261
Device,
262+
/// 'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
263+
DeviceNum,
249264
/// 'deviceptr' clause, allowed on Compute and Combined Constructs, plus
250265
/// 'data' and 'declare'.
251266
DevicePtr,
252267
/// 'device_resident' clause, allowed on the 'declare' construct.
253268
DeviceResident,
269+
/// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown',
270+
/// 'set', update', 'loop', 'routine', and Combined constructs.
271+
DeviceType,
272+
/// 'dtype' clause, an alias for 'device_type', stored separately for
273+
/// diagnostic purposes.
274+
DType,
275+
/// 'finalize' clause, allowed on 'exit data' directive.
276+
Finalize,
254277
/// 'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop',
255278
/// and 'serial loop' constructs.
256279
FirstPrivate,
280+
/// 'gang' clause, allowed on 'loop' and Combined constructs.
281+
Gang,
257282
/// 'host' clause, allowed on 'update' construct.
258283
Host,
284+
/// 'if' clause, allowed on all the Compute Constructs, Data Constructs,
285+
/// Executable Constructs, and Combined Constructs.
286+
If,
287+
/// 'if_present' clause, allowed on 'host_data' and 'update' directives.
288+
IfPresent,
289+
/// 'independent' clause, allowed on 'loop' directives.
290+
Independent,
259291
/// 'link' clause, allowed on 'declare' construct.
260292
Link,
261293
/// 'no_create' clause, allowed on allowed on Compute and Combined constructs,
262294
/// plus 'data'.
263295
NoCreate,
296+
/// 'nohost' clause, allowed on 'routine' directives.
297+
NoHost,
298+
/// 'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and
299+
/// 'kernels loop' constructs.
300+
NumGangs,
301+
/// 'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop',
302+
/// and 'kernels loop' constructs.
303+
NumWorkers,
264304
/// 'present' clause, allowed on Compute and Combined constructs, plus 'data'
265305
/// and 'declare'.
266306
Present,
267307
/// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel
268308
/// loop', and 'serial loop' constructs.
269309
Private,
270-
/// 'copyout' clause, allowed on Compute and Combined constructs, plus 'data',
271-
/// 'exit data', and 'declare'.
272-
CopyOut,
273-
/// 'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
274-
PCopyOut,
275-
/// 'copyout' clause alias 'present_or_copyout'. Preserved for diagnostic
276-
/// purposes.
277-
PresentOrCopyOut,
278-
/// 'copyin' clause, allowed on Compute and Combined constructs, plus 'data',
279-
/// 'enter data', and 'declare'.
280-
CopyIn,
281-
/// 'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
282-
PCopyIn,
283-
/// 'copyin' clause alias 'present_or_copyin'. Preserved for diagnostic
284-
/// purposes.
285-
PresentOrCopyIn,
286-
/// 'create' clause, allowed on Compute and Combined constructs, plus 'data',
287-
/// 'enter data', and 'declare'.
288-
Create,
289-
/// 'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
290-
PCreate,
291-
/// 'create' clause alias 'present_or_create'. Preserved for diagnostic
292-
/// purposes.
293-
PresentOrCreate,
294310
/// 'reduction' clause, allowed on Parallel, Serial, Loop, and the combined
295311
/// constructs.
296312
Reduction,
297-
/// 'collapse' clause, allowed on 'loop' and Combined constructs.
298-
Collapse,
299-
/// 'bind' clause, allowed on routine constructs.
300-
Bind,
313+
/// 'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
314+
Self,
315+
/// 'seq' clause, allowed on 'loop' and 'routine' directives.
316+
Seq,
317+
/// 'tile' clause, allowed on 'loop' and Combined constructs.
318+
Tile,
319+
/// 'use_device' clause, allowed on 'host_data' construct.
320+
UseDevice,
321+
/// 'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
322+
Vector,
301323
/// 'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop',
302324
/// and 'kernels loop' constructs.
303325
VectorLength,
304-
/// 'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and
305-
/// 'kernels loop' constructs.
306-
NumGangs,
307-
/// 'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop',
308-
/// and 'kernels loop' constructs.
309-
NumWorkers,
310-
/// 'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
311-
DeviceNum,
312-
/// 'default_async' clause, allowed on 'set' construct.
313-
DefaultAsync,
314-
/// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown',
315-
/// 'set', update', 'loop', 'routine', and Combined constructs.
316-
DeviceType,
317-
/// 'dtype' clause, an alias for 'device_type', stored separately for
318-
/// diagnostic purposes.
319-
DType,
320-
/// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined
321-
/// constructs.
322-
Async,
323-
/// 'tile' clause, allowed on 'loop' and Combined constructs.
324-
Tile,
325-
/// 'gang' clause, allowed on 'loop' and Combined constructs.
326-
Gang,
327326
/// 'wait' clause, allowed on Compute, Data, 'update', and Combined
328327
/// constructs.
329328
Wait,
329+
/// 'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
330+
Worker,
330331

331332
/// 'shortloop' is represented in the ACC.td file, but isn't present in the
332333
/// standard. This appears to be an old extension for the nvidia fortran

clang/lib/Sema/SemaOpenACCClauseAppertainment.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ struct LLVMDirectiveClauseRelationships {
7373
#include "llvm/Frontend/OpenACC/ACC.inc"
7474

7575
namespace {
76-
77-
// TODO: ERIHC: WOULD NEED ON DIRECTIVE_CLAUSE_MAP
7876
LLVMDirectiveClauseRelationships Relations[] =
7977
#define GEN_CLANG_DIRECTIVE_CLAUSE_MAP
8078
#include "llvm/Frontend/OpenACC/ACC.inc"
@@ -120,6 +118,20 @@ std::string getListOfClauses(AccClauseSet Set) {
120118
OS.flush();
121119
return OS.str();
122120
}
121+
122+
OpenACCClauseKind dealiasClauseKind(OpenACCClauseKind CK) {
123+
switch (CK) {
124+
default:
125+
return CK;
126+
#define VISIT_CLAUSE(NAME)
127+
#define CLAUSE_ALIAS(ALIAS, NAME, DEPRECATED) \
128+
case OpenACCClauseKind::ALIAS: \
129+
return OpenACCClauseKind::NAME;
130+
#include "clang/Basic/OpenACCClauses.def"
131+
}
132+
133+
return CK;
134+
}
123135
} // namespace
124136

125137
// Diagnoses if `Clauses` list doesn't have at least one of the required
@@ -136,7 +148,7 @@ bool SemaOpenACC::DiagnoseRequiredClauses(
136148
return false;
137149

138150
for (auto *C : Clauses) {
139-
if (Lists.Required.isSet(C->getClauseKind()))
151+
if (Lists.Required.isSet(dealiasClauseKind(C->getClauseKind())))
140152
return false;
141153
}
142154

@@ -153,12 +165,14 @@ bool SemaOpenACC::DiagnoseAllowedOnceClauses(
153165
if (DK == OpenACCDirectiveKind::Invalid || CK == OpenACCClauseKind::Invalid)
154166
return false;
155167

168+
OpenACCClauseKind Dealiased = dealiasClauseKind(CK);
169+
156170
const LLVMClauseLists &Lists = getListsForDirective(DK);
157171
if (!Lists.AllowedOnce.isSet(CK))
158172
return false;
159173

160174
auto Res = llvm::find_if(Clauses, [=](const OpenACCClause *C) {
161-
return C->getClauseKind() == CK;
175+
return dealiasClauseKind(C->getClauseKind()) == Dealiased;
162176
});
163177

164178
if (Res == Clauses.end())
@@ -178,13 +192,14 @@ bool SemaOpenACC::DiagnoseExclusiveClauses(
178192
return false;
179193

180194
const LLVMClauseLists &Lists = getListsForDirective(DK);
195+
OpenACCClauseKind Dealiased = dealiasClauseKind(CK);
181196

182197
// If this isn't on the list, this is fine.
183-
if (!Lists.AllowedExclusive.isSet(CK))
198+
if (!Lists.AllowedExclusive.isSet(Dealiased))
184199
return false;
185200

186201
for (const OpenACCClause *C : Clauses) {
187-
if (Lists.AllowedExclusive.isSet(C->getClauseKind())) {
202+
if (Lists.AllowedExclusive.isSet(dealiasClauseKind(C->getClauseKind()))) {
188203
Diag(ClauseLoc, diag::err_acc_clause_cannot_combine)
189204
<< CK << C->getClauseKind() << DK;
190205
Diag(C->getBeginLoc(), diag::note_acc_previous_clause_here);
@@ -203,9 +218,11 @@ bool SemaOpenACC::DiagnoseAllowedClauses(OpenACCDirectiveKind DK,
203218
if (DK == OpenACCDirectiveKind::Invalid || CK == OpenACCClauseKind::Invalid)
204219
return false;
205220
const LLVMClauseLists &Lists = getListsForDirective(DK);
221+
OpenACCClauseKind Dealiased = dealiasClauseKind(CK);
206222

207-
if (!Lists.Allowed.isSet(CK) && !Lists.AllowedOnce.isSet(CK) &&
208-
!Lists.AllowedExclusive.isSet(CK) && !Lists.Required.isSet(CK))
223+
if (!Lists.Allowed.isSet(Dealiased) && !Lists.AllowedOnce.isSet(Dealiased) &&
224+
!Lists.AllowedExclusive.isSet(Dealiased) &&
225+
!Lists.Required.isSet(Dealiased))
209226
return Diag(ClauseLoc, diag::err_acc_clause_appertainment) << DK << CK;
210227

211228
return false;

0 commit comments

Comments
 (0)