Skip to content

Commit ea64e66

Browse files
committed
[OPENMP]Initial support for error directive.
Differential Revision: https://reviews.llvm.org/D137209
1 parent a588cfe commit ea64e66

File tree

25 files changed

+336
-3
lines changed

25 files changed

+336
-3
lines changed

clang/include/clang-c/Index.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,11 @@ enum CXCursorKind {
19781978
*/
19791979
CXCursor_OMPParallelMaskedTaskLoopSimdDirective = 304,
19801980

1981-
CXCursor_LastStmt = CXCursor_OMPParallelMaskedTaskLoopSimdDirective,
1981+
/** OpenMP error directive.
1982+
*/
1983+
CXCursor_OMPErrorDirective = 305,
1984+
1985+
CXCursor_LastStmt = CXCursor_OMPErrorDirective,
19821986

19831987
/**
19841988
* Cursor that represents the translation unit itself.

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,10 @@ DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
31533153

31543154
DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
31553155
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
3156+
3157+
DEF_TRAVERSE_STMT(OMPErrorDirective,
3158+
{ TRY_TO(TraverseOMPExecutableDirective(S)); })
3159+
31563160
// OpenMP clauses.
31573161
template <typename Derived>
31583162
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6220,6 +6220,51 @@ class OMPTargetParallelGenericLoopDirective final : public OMPLoopDirective {
62206220
return T->getStmtClass() == OMPTargetParallelGenericLoopDirectiveClass;
62216221
}
62226222
};
6223+
6224+
/// This represents '#pragma omp error' directive.
6225+
///
6226+
/// \code
6227+
/// #pragma omp error
6228+
/// \endcode
6229+
class OMPErrorDirective final : public OMPExecutableDirective {
6230+
friend class ASTStmtReader;
6231+
friend class OMPExecutableDirective;
6232+
/// Build directive with the given start and end location.
6233+
///
6234+
/// \param StartLoc Starting location of the directive kind.
6235+
/// \param EndLoc Ending location of the directive.
6236+
///
6237+
OMPErrorDirective(SourceLocation StartLoc, SourceLocation EndLoc)
6238+
: OMPExecutableDirective(OMPErrorDirectiveClass, llvm::omp::OMPD_error,
6239+
StartLoc, EndLoc) {}
6240+
/// Build an empty directive.
6241+
///
6242+
explicit OMPErrorDirective()
6243+
: OMPExecutableDirective(OMPErrorDirectiveClass, llvm::omp::OMPD_error,
6244+
SourceLocation(), SourceLocation()) {}
6245+
6246+
public:
6247+
///
6248+
/// \param C AST context.
6249+
/// \param StartLoc Starting location of the directive kind.
6250+
/// \param EndLoc Ending Location of the directive.
6251+
/// \param Clauses List of clauses.
6252+
///
6253+
static OMPErrorDirective *Create(const ASTContext &C, SourceLocation StartLoc,
6254+
SourceLocation EndLoc,
6255+
ArrayRef<OMPClause *> Clauses);
6256+
6257+
/// Creates an empty directive.
6258+
///
6259+
/// \param C AST context.
6260+
///
6261+
static OMPErrorDirective *CreateEmpty(const ASTContext &C,
6262+
unsigned NumClauses, EmptyShell);
6263+
6264+
static bool classof(const Stmt *T) {
6265+
return T->getStmtClass() == OMPErrorDirectiveClass;
6266+
}
6267+
};
62236268
} // end namespace clang
62246269

62256270
#endif

clang/include/clang/Basic/StmtNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,4 @@ def OMPTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;
292292
def OMPTargetTeamsGenericLoopDirective : StmtNode<OMPLoopDirective>;
293293
def OMPParallelGenericLoopDirective : StmtNode<OMPLoopDirective>;
294294
def OMPTargetParallelGenericLoopDirective : StmtNode<OMPLoopDirective>;
295+
def OMPErrorDirective : StmtNode<OMPExecutableDirective>;

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11286,6 +11286,10 @@ class Sema final {
1128611286
/// Called on well-formed '\#pragma omp taskyield'.
1128711287
StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
1128811288
SourceLocation EndLoc);
11289+
/// Called on well-formed '\#pragma omp error'.
11290+
StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses,
11291+
SourceLocation StartLoc,
11292+
SourceLocation EndLoc);
1128911293
/// Called on well-formed '\#pragma omp barrier'.
1129011294
StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
1129111295
SourceLocation EndLoc);

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@ enum StmtCode {
19321932
STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE,
19331933
STMT_OMP_TASK_DIRECTIVE,
19341934
STMT_OMP_TASKYIELD_DIRECTIVE,
1935+
STMT_OMP_ERROR_DIRECTIVE,
19351936
STMT_OMP_BARRIER_DIRECTIVE,
19361937
STMT_OMP_TASKWAIT_DIRECTIVE,
19371938
STMT_OMP_FLUSH_DIRECTIVE,

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,21 @@ OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
744744
return new (C) OMPTaskyieldDirective();
745745
}
746746

747+
OMPErrorDirective *OMPErrorDirective::Create(const ASTContext &C,
748+
SourceLocation StartLoc,
749+
SourceLocation EndLoc,
750+
ArrayRef<OMPClause *> Clauses) {
751+
return createDirective<OMPErrorDirective>(
752+
C, Clauses, /*AssociatedStmt=*/nullptr, /*NumChildren=*/0, StartLoc,
753+
EndLoc);
754+
}
755+
756+
OMPErrorDirective *OMPErrorDirective::CreateEmpty(const ASTContext &C,
757+
unsigned NumClauses,
758+
EmptyShell) {
759+
return createEmptyDirective<OMPErrorDirective>(C, NumClauses);
760+
}
761+
747762
OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
748763
SourceLocation StartLoc,
749764
SourceLocation EndLoc) {

clang/lib/AST/StmtPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,11 @@ void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) {
843843
PrintOMPExecutableDirective(Node);
844844
}
845845

846+
void StmtPrinter::VisitOMPErrorDirective(OMPErrorDirective *Node) {
847+
Indent() << "#pragma omp error";
848+
PrintOMPExecutableDirective(Node);
849+
}
850+
846851
void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) {
847852
Indent() << "#pragma omp taskgroup";
848853
PrintOMPExecutableDirective(Node);

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
10141014
VisitOMPExecutableDirective(S);
10151015
}
10161016

1017+
void StmtProfiler::VisitOMPErrorDirective(const OMPErrorDirective *S) {
1018+
VisitOMPExecutableDirective(S);
1019+
}
10171020
void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
10181021
VisitOMPExecutableDirective(S);
10191022
if (const Expr *E = S->getReductionRef())

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ void clang::getOpenMPCaptureRegions(
763763
case OMPD_allocate:
764764
case OMPD_taskyield:
765765
case OMPD_barrier:
766+
case OMPD_error:
766767
case OMPD_taskwait:
767768
case OMPD_cancellation_point:
768769
case OMPD_cancel:

0 commit comments

Comments
 (0)