return true;
}
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
+ return true;
+}
+
template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
StmtRange children() { return StmtRange(); }
};
+/// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
+///
+/// \code
+/// #pragma omp atomic read
+/// \endcode
+/// In this example directive '#pragma omp atomic' has 'read' clause.
+///
+class OMPReadClause : public OMPClause {
+public:
+ /// \brief Build 'read' clause.
+ ///
+ /// \param StartLoc Starting location of the clause.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_read, StartLoc, EndLoc) {}
+
+ /// \brief Build an empty clause.
+ ///
+ OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_read;
+ }
+
+ StmtRange children() { return StmtRange(); }
+};
+
/// \brief This represents clause 'private' in the '#pragma omp ...' directives.
///
/// \code
return true;
}
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
+ return true;
+}
+
template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
"statement in 'omp parallel sections' directive must be enclosed into a section region">;
def err_omp_parallel_reduction_in_task_firstprivate : Error<
"argument of a reduction clause of a %0 construct must not appear in a firstprivate clause on a task construct">;
+def err_omp_atomic_read_not_expression_statement : Error<
+ "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">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
OPENMP_CLAUSE(untied, OMPUntiedClause)
OPENMP_CLAUSE(mergeable, OMPMergeableClause)
OPENMP_CLAUSE(flush, OMPFlushClause)
+OPENMP_CLAUSE(read, OMPReadClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
OPENMP_TASK_CLAUSE(untied)
OPENMP_TASK_CLAUSE(mergeable)
+// TODO More clauses allowed for OpenMP directive 'atomic'.
+OPENMP_ATOMIC_CLAUSE(read)
+
#undef OPENMP_SCHEDULE_KIND
#undef OPENMP_PROC_BIND_KIND
#undef OPENMP_DEFAULT_KIND
/// \brief Called on well-formed 'mergeable' clause.
OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed 'read' clause.
+ OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc,
+ SourceLocation EndLoc);
OMPClause *
ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
OS << "mergeable";
}
+void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
+
template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(),
void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
+void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
+
template<typename T>
void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
for (auto *I : Node->varlists())
case OMPC_untied:
case OMPC_mergeable:
case OMPC_flush:
+ case OMPC_read:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
case OMPC_untied:
case OMPC_mergeable:
case OMPC_flush:
+ case OMPC_read:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
/// | linear-clause | aligned-clause | collapse-clause |
/// lastprivate-clause | reduction-clause | proc_bind-clause |
/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
-/// mergeable-clause | flush-clause
+/// mergeable-clause | flush-clause | read-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
case OMPC_nowait:
case OMPC_untied:
case OMPC_mergeable:
+ case OMPC_read:
// 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]
/// mergeable-clause:
/// 'mergeable'
///
+/// read-clause:
+/// 'read'
+///
OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
SourceLocation Loc = Tok.getLocation();
ConsumeAnyToken();
Scope *CurScope;
SourceLocation ConstructLoc;
bool OrderedRegion;
+ SourceLocation AtomicClauseLoc;
SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
Scope *CurScope, SourceLocation Loc)
: SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified),
Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope),
- ConstructLoc(Loc), OrderedRegion(false) {}
+ ConstructLoc(Loc), OrderedRegion(false), AtomicClauseLoc() {}
SharingMapTy()
: SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified),
Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr),
- ConstructLoc(), OrderedRegion(false) {}
+ ConstructLoc(), OrderedRegion(false), AtomicClauseLoc() {}
};
typedef SmallVector<SharingMapTy, 64> StackTy;
return false;
}
+ /// \brief Checks if the 'atomic' construct has explicitly specified 'read',
+ /// 'update', 'write' or 'capture' clause.
+ bool hasAtomicClause() const {
+ return Stack.back().AtomicClauseLoc.isValid();
+ }
+ /// \brief Gets location of explicitly specified clause for 'atomic'
+ /// construct.
+ SourceLocation getAtomicClauseLoc() const {
+ return Stack.back().AtomicClauseLoc;
+ }
+ /// \brief Sets location of explicitly specified clause for 'atomic'
+ /// directive.
+ void setAtomicClauseLoc(SourceLocation Loc) {
+ Stack.back().AtomicClauseLoc = Loc;
+ }
+
Scope *getCurScope() const { return Stack.back().CurScope; }
Scope *getCurScope() { return Stack.back().CurScope; }
SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; }
SourceLocation StartLoc,
SourceLocation EndLoc) {
assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
+ auto CS = cast<CapturedStmt>(AStmt);
// 1.2.2 OpenMP Language Terminology
// Structured block - An executable statement with a single entry at the
// top and a single exit at the bottom.
// The point of exit cannot be a branch out of the structured block.
// longjmp() and throw() must not violate the entry/exit criteria.
// TODO further analysis of associated statements and clauses.
+ for (auto *C : Clauses) {
+ if (C->getClauseKind() == OMPC_read) {
+ if (!isa<Expr>(CS->getCapturedStmt())) {
+ Diag(CS->getCapturedStmt()->getLocStart(),
+ diag::err_omp_atomic_read_not_expression_statement);
+ return StmtError();
+ }
+ }
+ }
getCurFunction()->setHasBranchProtectedScope();
case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_flush:
+ case OMPC_read:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_flush:
+ case OMPC_read:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_flush:
+ case OMPC_read:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
case OMPC_mergeable:
Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc);
break;
+ case OMPC_read:
+ Res = ActOnOpenMPReadClause(StartLoc, EndLoc);
+ break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
return new (Context) OMPMergeableClause(StartLoc, EndLoc);
}
+OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ DSAStack->setAtomicClauseLoc(StartLoc);
+ return new (Context) OMPReadClause(StartLoc, EndLoc);
+}
+
OMPClause *Sema::ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
case OMPC_untied:
case OMPC_mergeable:
case OMPC_threadprivate:
+ case OMPC_read:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList);
}
-
-#undef DSAStack
return C;
}
+template <typename Derived>
+OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
+ // No need to rebuild this clause, no template-dependent parameters.
+ return C;
+}
+
template <typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
case OMPC_mergeable:
C = new (Context) OMPMergeableClause();
break;
+ case OMPC_read:
+ C = new (Context) OMPReadClause();
+ break;
case OMPC_private:
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
break;
void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
+void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {}
+
void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
unsigned NumVars = C->varlist_size();
void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
+void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {}
+
void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
Record.push_back(C->varlist_size());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
T a;
#pragma omp atomic
a++;
+#pragma omp atomic read
+ a = arg;
return T();
}
// CHECK: int a;
// CHECK-NEXT: #pragma omp atomic
// CHECK-NEXT: a++;
+// CHECK-NEXT: #pragma omp atomic read
+// CHECK-NEXT: a = arg;
// CHECK: T a;
// CHECK-NEXT: #pragma omp atomic
// CHECK-NEXT: a++;
+// CHECK-NEXT: #pragma omp atomic read
+// CHECK-NEXT: a = arg;
int main(int argc, char **argv) {
int a;
// CHECK: int a;
#pragma omp atomic
a++;
+#pragma omp atomic read
+ a = argc;
// CHECK-NEXT: #pragma omp atomic
// CHECK-NEXT: a++;
+ // CHECK-NEXT: #pragma omp atomic read
+ // CHECK-NEXT: a = argc;
return foo(a);
}
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s
int foo() {
- L1:
- foo();
- #pragma omp atomic
+L1:
+ foo();
+#pragma omp atomic
{
foo();
goto L1; // expected-error {{use of undeclared label 'L1'}}
}
goto L2; // expected-error {{use of undeclared label 'L2'}}
- #pragma omp atomic
+#pragma omp atomic
{
foo();
- L2:
+ L2:
foo();
}
return 0;
}
+
+template <class T>
+T read() {
+ 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 {{directive '#pragma omp atomic' cannot contain more than one 'read' clause}}
+#pragma omp atomic read read
+ a = b;
+
+ return T();
+}
+
+int 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 {{directive '#pragma omp atomic' cannot contain more than one 'read' clause}}
+#pragma omp atomic read read
+ a = b;
+
+ return read<int>();
+}
void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
+void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists())