}
template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *E : Node->varlists()) {
StmtRange children() { return StmtRange(); }
};
+/// \brief This represents 'capture' clause in the '#pragma omp atomic'
+/// directive.
+///
+/// \code
+/// #pragma omp atomic capture
+/// \endcode
+/// In this example directive '#pragma omp atomic' has 'capture' clause.
+///
+class OMPCaptureClause : public OMPClause {
+public:
+ /// \brief Build 'capture' clause.
+ ///
+ /// \param StartLoc Starting location of the clause.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
+
+ /// \brief Build an empty clause.
+ ///
+ OMPCaptureClause()
+ : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_capture;
+ }
+
+ StmtRange children() { return StmtRange(); }
+};
+
/// \brief This represents clause 'private' in the '#pragma omp ...' directives.
///
/// \code
}
template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *E : Node->varlists()) {
def err_omp_atomic_update_not_expression_statement : Error<
"the statement for 'atomic%select{| update}0' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x',"
" where x is an l-value expression with scalar type">;
+def err_omp_atomic_capture_not_expression_statement : Error<
+ "the statement for 'atomic capture' must be an expression statement of form 'v = ++x;', 'v = --x;', 'v = x++;', 'v = x--;', 'v = x binop= expr;', 'v = x = x binop expr' or 'v = x = expr binop x',"
+ " where x and v are both l-value expressions with scalar type">;
+def err_omp_atomic_capture_not_compound_statement : Error<
+ "the statement for 'atomic capture' must be a compound statement of form '{v = x; x binop= expr;}', '{x binop= expr; v = x;}',"
+ " '{v = x; x = x binop expr;}', '{v = x; x = expr binop x;}', '{x = x binop expr; v = x;}', '{x = expr binop x; v = x;}' or '{v = x; x = expr;}',"
+ " '{v = x; x++;}', '{v = x; ++x;}', '{++x; v = x;}', '{x++; v = x;}', '{v = x; x--;}', '{v = x; --x;}', '{--x; v = x;}', '{x--; v = x;}'"
+ " where x is an l-value expression with scalar type">;
def err_omp_atomic_several_clauses : Error<
"directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause">;
def note_omp_atomic_previous_clause : Note<
OPENMP_CLAUSE(read, OMPReadClause)
OPENMP_CLAUSE(write, OMPWriteClause)
OPENMP_CLAUSE(update, OMPUpdateClause)
+OPENMP_CLAUSE(capture, OMPCaptureClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
OPENMP_ATOMIC_CLAUSE(read)
OPENMP_ATOMIC_CLAUSE(write)
OPENMP_ATOMIC_CLAUSE(update)
+OPENMP_ATOMIC_CLAUSE(capture)
#undef OPENMP_SCHEDULE_KIND
#undef OPENMP_PROC_BIND_KIND
/// \brief Called on well-formed 'update' clause.
OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed 'capture' clause.
+ OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc,
+ SourceLocation EndLoc);
OMPClause *
ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
OS << "update";
}
+void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
+ OS << "capture";
+}
+
template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(),
void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
+void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
+
template<typename T>
void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
for (auto *I : Node->varlists())
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
/// lastprivate-clause | reduction-clause | proc_bind-clause |
/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
/// mergeable-clause | flush-clause | read-clause | write-clause |
-/// update-clause
+/// update-clause | capture-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
// OpenMP [2.7.1, Restrictions, p. 9]
// Only one ordered clause can appear on a loop directive.
// OpenMP [2.7.1, Restrictions, C/C++, p. 4]
SourceLocation AtomicKindLoc;
for (auto *C : Clauses) {
if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write ||
- C->getClauseKind() == OMPC_update) {
+ C->getClauseKind() == OMPC_update ||
+ C->getClauseKind() == OMPC_capture) {
if (AtomicKind != OMPC_unknown) {
Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses)
<< SourceRange(C->getLocStart(), C->getLocEnd());
}
}
}
+ auto Body = CS->getCapturedStmt();
if (AtomicKind == OMPC_read) {
- if (!isa<Expr>(CS->getCapturedStmt())) {
- Diag(CS->getCapturedStmt()->getLocStart(),
+ if (!isa<Expr>(Body)) {
+ Diag(Body->getLocStart(),
diag::err_omp_atomic_read_not_expression_statement);
return StmtError();
}
} else if (AtomicKind == OMPC_write) {
- if (!isa<Expr>(CS->getCapturedStmt())) {
- Diag(CS->getCapturedStmt()->getLocStart(),
+ if (!isa<Expr>(Body)) {
+ Diag(Body->getLocStart(),
diag::err_omp_atomic_write_not_expression_statement);
return StmtError();
}
} else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) {
- if (!isa<Expr>(CS->getCapturedStmt())) {
- Diag(CS->getCapturedStmt()->getLocStart(),
+ if (!isa<Expr>(Body)) {
+ Diag(Body->getLocStart(),
diag::err_omp_atomic_update_not_expression_statement)
<< (AtomicKind == OMPC_update);
return StmtError();
}
+ } else if (AtomicKind == OMPC_capture) {
+ if (isa<Expr>(Body) && !isa<BinaryOperator>(Body)) {
+ Diag(Body->getLocStart(),
+ diag::err_omp_atomic_capture_not_expression_statement);
+ return StmtError();
+ } else if (!isa<Expr>(Body) && !isa<CompoundStmt>(Body)) {
+ Diag(Body->getLocStart(),
+ diag::err_omp_atomic_capture_not_compound_statement);
+ return StmtError();
+ }
}
getCurFunction()->setHasBranchProtectedScope();
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_update:
Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc);
break;
+ case OMPC_capture:
+ Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc);
+ break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
return new (Context) OMPUpdateClause(StartLoc, EndLoc);
}
+OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ return new (Context) OMPCaptureClause(StartLoc, EndLoc);
+}
+
OMPClause *Sema::ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
case OMPC_read:
case OMPC_write:
case OMPC_update:
+ case OMPC_capture:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
template <typename Derived>
OMPClause *
+TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
+ // No need to rebuild this clause, no template-dependent parameters.
+ return C;
+}
+
+template <typename Derived>
+OMPClause *
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
llvm::SmallVector<Expr *, 16> Vars;
Vars.reserve(C->varlist_size());
case OMPC_update:
C = new (Context) OMPUpdateClause();
break;
+ case OMPC_capture:
+ C = new (Context) OMPCaptureClause();
+ break;
case OMPC_private:
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
break;
void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {}
+void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {}
+
void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
unsigned NumVars = C->varlist_size();
void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {}
+void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {}
+
void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
Record.push_back(C->varlist_size());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
template <class T>
T foo(T argc) {
+ T b = T();
T a = T();
#pragma omp atomic
a++;
a = argc + argc;
#pragma omp atomic update
a = a + argc;
+#pragma omp atomic capture
+ a = b++;
+#pragma omp atomic capture
+ {
+ a = b;
+ b++;
+ }
return T();
}
// CHECK-NEXT: a = argc + argc;
// CHECK-NEXT: #pragma omp atomic update
// CHECK-NEXT: a = a + argc;
+// CHECK-NEXT: #pragma omp atomic capture
+// CHECK-NEXT: a = b++;
+// CHECK-NEXT: #pragma omp atomic capture
+// CHECK-NEXT: {
+// CHECK-NEXT: a = b;
+// CHECK-NEXT: b++;
+// CHECK-NEXT: }
// CHECK: T a = T();
// CHECK-NEXT: #pragma omp atomic
// CHECK-NEXT: a++;
// CHECK-NEXT: a = argc + argc;
// CHECK-NEXT: #pragma omp atomic update
// CHECK-NEXT: a = a + argc;
+// CHECK-NEXT: #pragma omp atomic capture
+// CHECK-NEXT: a = b++;
+// CHECK-NEXT: #pragma omp atomic capture
+// CHECK-NEXT: {
+// CHECK-NEXT: a = b;
+// CHECK-NEXT: b++;
+// CHECK-NEXT: }
int main(int argc, char **argv) {
+ int b = 0;
int a = 0;
// CHECK: int a = 0;
#pragma omp atomic
a = argc + argc;
#pragma omp atomic update
a = a + argc;
+#pragma omp atomic capture
+ a = b++;
+#pragma omp atomic capture
+ {
+ a = b;
+ b++;
+ }
// CHECK-NEXT: #pragma omp atomic
// CHECK-NEXT: a++;
// CHECK-NEXT: #pragma omp atomic read
// CHECK-NEXT: a = argc + argc;
// CHECK-NEXT: #pragma omp atomic update
// CHECK-NEXT: a = a + argc;
+ // CHECK-NEXT: #pragma omp atomic capture
+ // CHECK-NEXT: a = b++;
+ // CHECK-NEXT: #pragma omp atomic capture
+ // CHECK-NEXT: {
+ // CHECK-NEXT: a = b;
+ // CHECK-NEXT: b++;
+ // CHECK-NEXT: }
return foo(a);
}
L1:
foo();
#pragma omp atomic
-// expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
{
foo();
goto L1; // expected-error {{use of undeclared label 'L1'}}
}
goto L2; // expected-error {{use of undeclared label 'L2'}}
#pragma omp atomic
-// expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
{
foo();
L2:
T a, b = 0;
// Test for atomic read
#pragma omp atomic read
-// expected-error@+1 {{the statement for 'atomic read' must be an expression statement of form 'v = x;', where v and x are both l-value expressions with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic read' must be an expression statement of form 'v = x;', where v and x are both l-value expressions with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'read' clause}}
#pragma omp atomic read read
int a, b = 0;
// Test for atomic read
#pragma omp atomic read
-// expected-error@+1 {{the statement for 'atomic read' must be an expression statement of form 'v = x;', where v and x are both l-value expressions with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic read' must be an expression statement of form 'v = x;', where v and x are both l-value expressions with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'read' clause}}
#pragma omp atomic read read
T a, b = 0;
// Test for atomic write
#pragma omp atomic write
-// expected-error@+1 {{the statement for 'atomic write' must be an expression statement of form 'x = expr;', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic write' must be an expression statement of form 'x = expr;', where x is an l-value expression with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'write' clause}}
#pragma omp atomic write write
int a, b = 0;
// Test for atomic write
#pragma omp atomic write
-// expected-error@+1 {{the statement for 'atomic write' must be an expression statement of form 'x = expr;', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic write' must be an expression statement of form 'x = expr;', where x is an l-value expression with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'write' clause}}
#pragma omp atomic write write
T a, b = 0;
// Test for atomic update
#pragma omp atomic update
-// expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'update' clause}}
#pragma omp atomic update update
a += b;
#pragma omp atomic
-// expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
;
return T();
int a, b = 0;
// Test for atomic update
#pragma omp atomic update
-// expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
;
// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'update' clause}}
#pragma omp atomic update update
a += b;
#pragma omp atomic
-// expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
+ // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}}
;
return update<int>();
}
template <class T>
+T capture() {
+ T a, b = 0;
+// Test for atomic capture
+#pragma omp atomic capture
+ // expected-error@+1 {{the statement for 'atomic capture' must be an expression statement of form 'v = ++x;', 'v = --x;', 'v = x++;', 'v = x--;', 'v = x binop= expr;', 'v = x = x binop expr' or 'v = x = expr binop x', where x and v are both l-value expressions with scalar type}}
+ ++a;
+#pragma omp atomic capture
+ // expected-error@+1 {{the statement for 'atomic capture' must be a compound statement of form '{v = x; x binop= expr;}', '{x binop= expr; v = x;}', '{v = x; x = x binop expr;}', '{v = x; x = expr binop x;}', '{x = x binop expr; v = x;}', '{x = expr binop x; v = x;}' or '{v = x; x = expr;}', '{v = x; x++;}', '{v = x; ++x;}', '{++x; v = x;}', '{x++; v = x;}', '{v = x; x--;}', '{v = x; --x;}', '{--x; v = x;}', '{x--; v = x;}' where x is an l-value expression with scalar type}}
+ ;
+// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
+#pragma omp atomic capture capture
+ a = ++b;
+
+ return T();
+}
+
+int capture() {
+ int a, b = 0;
+// Test for atomic capture
+#pragma omp atomic capture
+ // expected-error@+1 {{the statement for 'atomic capture' must be an expression statement of form 'v = ++x;', 'v = --x;', 'v = x++;', 'v = x--;', 'v = x binop= expr;', 'v = x = x binop expr' or 'v = x = expr binop x', where x and v are both l-value expressions with scalar type}}
+ ++a;
+#pragma omp atomic capture
+ // expected-error@+1 {{the statement for 'atomic capture' must be a compound statement of form '{v = x; x binop= expr;}', '{x binop= expr; v = x;}', '{v = x; x = x binop expr;}', '{v = x; x = expr binop x;}', '{x = x binop expr; v = x;}', '{x = expr binop x; v = x;}' or '{v = x; x = expr;}', '{v = x; x++;}', '{v = x; ++x;}', '{++x; v = x;}', '{x++; v = x;}', '{v = x; x--;}', '{v = x; --x;}', '{--x; v = x;}', '{x--; v = x;}' where x is an l-value expression with scalar type}}
+ ;
+// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
+#pragma omp atomic capture capture
+ a = ++b;
+
+ return capture<int>();
+}
+
+template <class T>
T mixed() {
T a, b = T();
// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
// expected-note@+1 2 {{'update' clause used here}}
#pragma omp atomic update read
a += b;
+// expected-error@+2 2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
+// expected-note@+1 2 {{'capture' clause used here}}
+#pragma omp atomic capture read
+ a = ++b;
return T();
}
// expected-note@+1 {{'write' clause used here}}
#pragma omp atomic write update
a = b;
-// expected-note@+1 {{in instantiation of function template specialization 'mixed<int>' requested here}}
+// expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause}}
+// expected-note@+1 {{'write' clause used here}}
+#pragma omp atomic write capture
+ a = b;
+ // expected-note@+1 {{in instantiation of function template specialization 'mixed<int>' requested here}}
return mixed<int>();
}
void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {}
+void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists())