@@ -20,7 +20,7 @@ using namespace clang;
2020bool OpenACCClauseWithParams::classof (const OpenACCClause *C) {
2121 return OpenACCDeviceTypeClause::classof (C) ||
2222 OpenACCClauseWithCondition::classof (C) ||
23- OpenACCClauseWithExprs::classof (C);
23+ OpenACCClauseWithExprs::classof (C) || OpenACCSelfClause::classof (C) ;
2424}
2525bool OpenACCClauseWithExprs::classof (const OpenACCClause *C) {
2626 return OpenACCWaitClause::classof (C) || OpenACCNumGangsClause::classof (C) ||
@@ -41,7 +41,7 @@ bool OpenACCClauseWithVarList::classof(const OpenACCClause *C) {
4141 OpenACCReductionClause::classof (C) || OpenACCCreateClause::classof (C);
4242}
4343bool OpenACCClauseWithCondition::classof (const OpenACCClause *C) {
44- return OpenACCIfClause::classof (C) || OpenACCSelfClause::classof (C) ;
44+ return OpenACCIfClause::classof (C);
4545}
4646bool OpenACCClauseWithSingleIntExpr::classof (const OpenACCClause *C) {
4747 return OpenACCNumWorkersClause::classof (C) ||
@@ -87,19 +87,43 @@ OpenACCSelfClause *OpenACCSelfClause::Create(const ASTContext &C,
8787 SourceLocation LParenLoc,
8888 Expr *ConditionExpr,
8989 SourceLocation EndLoc) {
90- void *Mem = C.Allocate (sizeof (OpenACCIfClause), alignof (OpenACCIfClause ));
90+ void *Mem = C.Allocate (OpenACCSelfClause::totalSizeToAlloc<Expr *>( 1 ));
9191 return new (Mem)
9292 OpenACCSelfClause (BeginLoc, LParenLoc, ConditionExpr, EndLoc);
9393}
9494
95+ OpenACCSelfClause *OpenACCSelfClause::Create (const ASTContext &C,
96+ SourceLocation BeginLoc,
97+ SourceLocation LParenLoc,
98+ ArrayRef<Expr *> VarList,
99+ SourceLocation EndLoc) {
100+ void *Mem =
101+ C.Allocate (OpenACCSelfClause::totalSizeToAlloc<Expr *>(VarList.size ()));
102+ return new (Mem) OpenACCSelfClause (BeginLoc, LParenLoc, VarList, EndLoc);
103+ }
104+
105+ OpenACCSelfClause::OpenACCSelfClause (SourceLocation BeginLoc,
106+ SourceLocation LParenLoc,
107+ llvm::ArrayRef<Expr *> VarList,
108+ SourceLocation EndLoc)
109+ : OpenACCClauseWithParams(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
110+ EndLoc),
111+ HasConditionExpr(std::nullopt ), NumExprs(VarList.size()) {
112+ std::uninitialized_copy (VarList.begin (), VarList.end (),
113+ getTrailingObjects<Expr *>());
114+ }
115+
95116OpenACCSelfClause::OpenACCSelfClause (SourceLocation BeginLoc,
96117 SourceLocation LParenLoc,
97118 Expr *ConditionExpr, SourceLocation EndLoc)
98- : OpenACCClauseWithCondition(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
99- ConditionExpr, EndLoc) {
119+ : OpenACCClauseWithParams(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
120+ EndLoc),
121+ HasConditionExpr(ConditionExpr != nullptr ), NumExprs(1 ) {
100122 assert ((!ConditionExpr || ConditionExpr->isInstantiationDependent () ||
101123 ConditionExpr->getType ()->isScalarType ()) &&
102124 " Condition expression type not scalar/dependent" );
125+ std::uninitialized_copy (&ConditionExpr, &ConditionExpr + 1 ,
126+ getTrailingObjects<Expr *>());
103127}
104128
105129OpenACCClause::child_range OpenACCClause::children () {
@@ -555,9 +579,17 @@ void OpenACCClausePrinter::VisitIfClause(const OpenACCIfClause &C) {
555579
556580void OpenACCClausePrinter::VisitSelfClause (const OpenACCSelfClause &C) {
557581 OS << " self" ;
558- if (const Expr *CondExpr = C.getConditionExpr ()) {
582+
583+ if (C.isConditionExprClause ()) {
584+ if (const Expr *CondExpr = C.getConditionExpr ()) {
585+ OS << " (" ;
586+ printExpr (CondExpr);
587+ OS << " )" ;
588+ }
589+ } else {
559590 OS << " (" ;
560- printExpr (CondExpr);
591+ llvm::interleaveComma (C.getVarList (), OS,
592+ [&](const Expr *E) { printExpr (E); });
561593 OS << " )" ;
562594 }
563595}
0 commit comments