Skip to content

Commit 6317742

Browse files
committed
[OpenACC][NFC] Fix isa behavior for OpenACC types
I discovered while working on a different patch that I'd not implemented the 'classof' for any of the Clauses, which resulted in 'isa' always returning 'true' for all of the types. This patch goes through all the existing clauses and adds 'classof' such that it will work correctly. Additionally, in doing this, I found a bug where I was doing a cast to the wrong type in the ASTWriter, so this fixes that problem as well.
1 parent 8fc9e3d commit 6317742

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OpenACCClause {
3636
SourceLocation getBeginLoc() const { return Location.getBegin(); }
3737
SourceLocation getEndLoc() const { return Location.getEnd(); }
3838

39-
static bool classof(const OpenACCClause *) { return true; }
39+
static bool classof(const OpenACCClause *) { return false; }
4040

4141
using child_iterator = StmtIterator;
4242
using const_child_iterator = ConstStmtIterator;
@@ -63,6 +63,8 @@ class OpenACCClauseWithParams : public OpenACCClause {
6363
: OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
6464

6565
public:
66+
static bool classof(const OpenACCClause *C);
67+
6668
SourceLocation getLParenLoc() const { return LParenLoc; }
6769

6870
child_range children() {
@@ -92,6 +94,9 @@ class OpenACCDefaultClause : public OpenACCClauseWithParams {
9294
}
9395

9496
public:
97+
static bool classof(const OpenACCClause *C) {
98+
return C->getClauseKind() == OpenACCClauseKind::Default;
99+
}
95100
OpenACCDefaultClauseKind getDefaultClauseKind() const {
96101
return DefaultClauseKind;
97102
}
@@ -116,6 +121,8 @@ class OpenACCClauseWithCondition : public OpenACCClauseWithParams {
116121
ConditionExpr(ConditionExpr) {}
117122

118123
public:
124+
static bool classof(const OpenACCClause *C);
125+
119126
bool hasConditionExpr() const { return ConditionExpr; }
120127
const Expr *getConditionExpr() const { return ConditionExpr; }
121128
Expr *getConditionExpr() { return ConditionExpr; }
@@ -143,6 +150,9 @@ class OpenACCIfClause : public OpenACCClauseWithCondition {
143150
Expr *ConditionExpr, SourceLocation EndLoc);
144151

145152
public:
153+
static bool classof(const OpenACCClause *C) {
154+
return C->getClauseKind() == OpenACCClauseKind::If;
155+
}
146156
static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
147157
SourceLocation LParenLoc, Expr *ConditionExpr,
148158
SourceLocation EndLoc);
@@ -154,6 +164,9 @@ class OpenACCSelfClause : public OpenACCClauseWithCondition {
154164
Expr *ConditionExpr, SourceLocation EndLoc);
155165

156166
public:
167+
static bool classof(const OpenACCClause *C) {
168+
return C->getClauseKind() == OpenACCClauseKind::Self;
169+
}
157170
static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
158171
SourceLocation LParenLoc,
159172
Expr *ConditionExpr, SourceLocation EndLoc);
@@ -180,6 +193,7 @@ class OpenACCClauseWithExprs : public OpenACCClauseWithParams {
180193
llvm::ArrayRef<Expr *> getExprs() const { return Exprs; }
181194

182195
public:
196+
static bool classof(const OpenACCClause *C);
183197
child_range children() {
184198
return child_range(reinterpret_cast<Stmt **>(Exprs.begin()),
185199
reinterpret_cast<Stmt **>(Exprs.end()));
@@ -214,6 +228,9 @@ class OpenACCWaitClause final
214228
}
215229

216230
public:
231+
static bool classof(const OpenACCClause *C) {
232+
return C->getClauseKind() == OpenACCClauseKind::Wait;
233+
}
217234
static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
218235
SourceLocation LParenLoc, Expr *DevNumExpr,
219236
SourceLocation QueuesLoc,
@@ -246,6 +263,9 @@ class OpenACCNumGangsClause final
246263
}
247264

248265
public:
266+
static bool classof(const OpenACCClause *C) {
267+
return C->getClauseKind() == OpenACCClauseKind::NumGangs;
268+
}
249269
static OpenACCNumGangsClause *
250270
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
251271
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
@@ -275,6 +295,7 @@ class OpenACCClauseWithSingleIntExpr : public OpenACCClauseWithExprs {
275295
}
276296

277297
public:
298+
static bool classof(const OpenACCClause *C);
278299
bool hasIntExpr() const { return !getExprs().empty(); }
279300
const Expr *getIntExpr() const {
280301
return hasIntExpr() ? getExprs()[0] : nullptr;
@@ -288,6 +309,9 @@ class OpenACCNumWorkersClause : public OpenACCClauseWithSingleIntExpr {
288309
Expr *IntExpr, SourceLocation EndLoc);
289310

290311
public:
312+
static bool classof(const OpenACCClause *C) {
313+
return C->getClauseKind() == OpenACCClauseKind::NumWorkers;
314+
}
291315
static OpenACCNumWorkersClause *Create(const ASTContext &C,
292316
SourceLocation BeginLoc,
293317
SourceLocation LParenLoc,
@@ -299,6 +323,9 @@ class OpenACCVectorLengthClause : public OpenACCClauseWithSingleIntExpr {
299323
Expr *IntExpr, SourceLocation EndLoc);
300324

301325
public:
326+
static bool classof(const OpenACCClause *C) {
327+
return C->getClauseKind() == OpenACCClauseKind::VectorLength;
328+
}
302329
static OpenACCVectorLengthClause *
303330
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
304331
Expr *IntExpr, SourceLocation EndLoc);
@@ -309,6 +336,9 @@ class OpenACCAsyncClause : public OpenACCClauseWithSingleIntExpr {
309336
Expr *IntExpr, SourceLocation EndLoc);
310337

311338
public:
339+
static bool classof(const OpenACCClause *C) {
340+
return C->getClauseKind() == OpenACCClauseKind::Async;
341+
}
312342
static OpenACCAsyncClause *Create(const ASTContext &C,
313343
SourceLocation BeginLoc,
314344
SourceLocation LParenLoc, Expr *IntExpr,
@@ -326,6 +356,7 @@ class OpenACCClauseWithVarList : public OpenACCClauseWithExprs {
326356
: OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
327357

328358
public:
359+
static bool classof(const OpenACCClause *C);
329360
ArrayRef<Expr *> getVarList() { return getExprs(); }
330361
ArrayRef<Expr *> getVarList() const { return getExprs(); }
331362
};
@@ -344,6 +375,9 @@ class OpenACCPrivateClause final
344375
}
345376

346377
public:
378+
static bool classof(const OpenACCClause *C) {
379+
return C->getClauseKind() == OpenACCClauseKind::Private;
380+
}
347381
static OpenACCPrivateClause *
348382
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
349383
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -363,6 +397,9 @@ class OpenACCFirstPrivateClause final
363397
}
364398

365399
public:
400+
static bool classof(const OpenACCClause *C) {
401+
return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
402+
}
366403
static OpenACCFirstPrivateClause *
367404
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
368405
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -382,6 +419,9 @@ class OpenACCDevicePtrClause final
382419
}
383420

384421
public:
422+
static bool classof(const OpenACCClause *C) {
423+
return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
424+
}
385425
static OpenACCDevicePtrClause *
386426
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
387427
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -401,6 +441,9 @@ class OpenACCAttachClause final
401441
}
402442

403443
public:
444+
static bool classof(const OpenACCClause *C) {
445+
return C->getClauseKind() == OpenACCClauseKind::Attach;
446+
}
404447
static OpenACCAttachClause *
405448
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
406449
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -420,6 +463,9 @@ class OpenACCNoCreateClause final
420463
}
421464

422465
public:
466+
static bool classof(const OpenACCClause *C) {
467+
return C->getClauseKind() == OpenACCClauseKind::NoCreate;
468+
}
423469
static OpenACCNoCreateClause *
424470
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
425471
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -439,6 +485,9 @@ class OpenACCPresentClause final
439485
}
440486

441487
public:
488+
static bool classof(const OpenACCClause *C) {
489+
return C->getClauseKind() == OpenACCClauseKind::Present;
490+
}
442491
static OpenACCPresentClause *
443492
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
444493
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
@@ -462,6 +511,11 @@ class OpenACCCopyClause final
462511
}
463512

464513
public:
514+
static bool classof(const OpenACCClause *C) {
515+
return C->getClauseKind() == OpenACCClauseKind::Copy ||
516+
C->getClauseKind() == OpenACCClauseKind::PCopy ||
517+
C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
518+
}
465519
static OpenACCCopyClause *
466520
Create(const ASTContext &C, OpenACCClauseKind Spelling,
467521
SourceLocation BeginLoc, SourceLocation LParenLoc,
@@ -488,6 +542,11 @@ class OpenACCCopyInClause final
488542
}
489543

490544
public:
545+
static bool classof(const OpenACCClause *C) {
546+
return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
547+
C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
548+
C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
549+
}
491550
bool isReadOnly() const { return IsReadOnly; }
492551
static OpenACCCopyInClause *
493552
Create(const ASTContext &C, OpenACCClauseKind Spelling,
@@ -515,6 +574,11 @@ class OpenACCCopyOutClause final
515574
}
516575

517576
public:
577+
static bool classof(const OpenACCClause *C) {
578+
return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
579+
C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
580+
C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
581+
}
518582
bool isZero() const { return IsZero; }
519583
static OpenACCCopyOutClause *
520584
Create(const ASTContext &C, OpenACCClauseKind Spelling,
@@ -542,6 +606,11 @@ class OpenACCCreateClause final
542606
}
543607

544608
public:
609+
static bool classof(const OpenACCClause *C) {
610+
return C->getClauseKind() == OpenACCClauseKind::Create ||
611+
C->getClauseKind() == OpenACCClauseKind::PCreate ||
612+
C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
613+
}
545614
bool isZero() const { return IsZero; }
546615
static OpenACCCreateClause *
547616
Create(const ASTContext &C, OpenACCClauseKind Spelling,

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
9393
}
9494

9595
public:
96+
static bool classof(const Stmt *T) {
97+
return false;
98+
}
99+
96100
child_range children() {
97101
if (getAssociatedStmt())
98102
return child_range(&AssociatedStmt, &AssociatedStmt + 1);

clang/lib/AST/OpenACCClause.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,33 @@
1717

1818
using namespace clang;
1919

20+
bool OpenACCClauseWithParams::classof(const OpenACCClause *C) {
21+
return OpenACCClauseWithCondition::classof(C) ||
22+
OpenACCClauseWithExprs::classof(C);
23+
}
24+
bool OpenACCClauseWithExprs::classof(const OpenACCClause *C) {
25+
return OpenACCWaitClause::classof(C) || OpenACCNumGangsClause::classof(C) ||
26+
OpenACCClauseWithSingleIntExpr::classof(C) ||
27+
OpenACCClauseWithVarList::classof(C);
28+
}
29+
bool OpenACCClauseWithVarList::classof(const OpenACCClause *C) {
30+
return OpenACCPrivateClause::classof(C) ||
31+
OpenACCFirstPrivateClause::classof(C) ||
32+
OpenACCDevicePtrClause::classof(C) ||
33+
OpenACCDevicePtrClause::classof(C) ||
34+
OpenACCAttachClause::classof(C) || OpenACCNoCreateClause::classof(C) ||
35+
OpenACCPresentClause::classof(C) || OpenACCCopyClause::classof(C) ||
36+
OpenACCCopyInClause::classof(C) || OpenACCCopyOutClause::classof(C) ||
37+
OpenACCCreateClause::classof(C);
38+
}
39+
bool OpenACCClauseWithCondition::classof(const OpenACCClause *C) {
40+
return OpenACCIfClause::classof(C) || OpenACCSelfClause::classof(C);
41+
}
42+
bool OpenACCClauseWithSingleIntExpr::classof(const OpenACCClause *C) {
43+
return OpenACCNumWorkersClause::classof(C) ||
44+
OpenACCVectorLengthClause::classof(C) ||
45+
OpenACCAsyncClause::classof(C);
46+
}
2047
OpenACCDefaultClause *OpenACCDefaultClause::Create(const ASTContext &C,
2148
OpenACCDefaultClauseKind K,
2249
SourceLocation BeginLoc,

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7816,7 +7816,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
78167816
return;
78177817
}
78187818
case OpenACCClauseKind::Self: {
7819-
const auto *SC = cast<OpenACCIfClause>(C);
7819+
const auto *SC = cast<OpenACCSelfClause>(C);
78207820
writeSourceLocation(SC->getLParenLoc());
78217821
writeBool(SC->hasConditionExpr());
78227822
if (SC->hasConditionExpr())

0 commit comments

Comments
 (0)