From 154210ac5cbccd52c070afbd3b1ec86b21afafac Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 13 Feb 2014 05:29:23 +0000 Subject: [PATCH] [OPENMP] 'if' clause support (no CodeGen support) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201297 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DataRecursiveASTVisitor.h | 6 +++ include/clang/AST/RecursiveASTVisitor.h | 6 +++ include/clang/AST/StmtOpenMP.h | 54 +++++++++++++++++++++ include/clang/Basic/DiagnosticParseKinds.td | 2 + include/clang/Basic/OpenMPKinds.def | 2 + include/clang/Sema/Sema.h | 10 ++++ lib/AST/StmtPrinter.cpp | 12 ++++- lib/AST/StmtProfile.cpp | 5 ++ lib/Basic/OpenMPKinds.cpp | 2 + lib/Parse/ParseOpenMP.cpp | 49 +++++++++++++++++-- lib/Sema/SemaOpenMP.cpp | 48 +++++++++++++++++- lib/Sema/TreeTransform.h | 19 ++++++++ lib/Serialization/ASTReaderStmt.cpp | 8 +++ lib/Serialization/ASTWriterStmt.cpp | 5 ++ test/OpenMP/parallel_ast_print.cpp | 12 ++--- test/OpenMP/parallel_if_messages.cpp | 43 ++++++++++++++++ tools/libclang/CIndex.cpp | 4 ++ 17 files changed, 275 insertions(+), 12 deletions(-) create mode 100644 test/OpenMP/parallel_if_messages.cpp diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 068fe08cfd..df26f0a04d 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2352,6 +2352,12 @@ bool DataRecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { return true; } +template +bool DataRecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { + TraverseStmt(C->getCondition()); + return true; +} + template bool DataRecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { return true; diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 75774451c8..f1396aabde 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2376,6 +2376,12 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { return true; } +template +bool RecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { + TraverseStmt(C->getCondition()); + return true; +} + template bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { return true; diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index 5ed5f25023..ef59fd6016 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -121,6 +121,60 @@ public: } }; +/// \brief This represents 'if' clause in the '#pragma omp ...' directive. +/// +/// \code +/// #pragma omp parallel if(a > 5) +/// \endcode +/// In this example directive '#pragma omp parallel' has simple 'if' +/// clause with condition 'a > 5'. +/// +class OMPIfClause : public OMPClause { + friend class OMPClauseReader; + /// \brief Location of '('. + SourceLocation LParenLoc; + /// \brief Condition of the 'if' clause. + Stmt *Condition; + + /// \brief Set condition. + /// + void setCondition(Expr *Cond) { Condition = Cond; } +public: + /// \brief Build 'if' clause with condition \a Cond. + /// + /// \param StartLoc Starting location of the clause. + /// \param LParenLoc Location of '('. + /// \param Cond Condition of the clause. + /// \param EndLoc Ending location of the clause. + /// + OMPIfClause(Expr *Cond, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation EndLoc) + : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc), + Condition(Cond) { } + + /// \brief Build an empty clause. + /// + OMPIfClause() + : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), + LParenLoc(SourceLocation()), Condition(0) { } + + /// \brief Sets the location of '('. + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + /// \brief Returns the location of '('. + SourceLocation getLParenLoc() const { return LParenLoc; } + + /// \brief Returns condition. + Expr *getCondition() const { return cast_or_null(Condition); } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_if; + } + + StmtRange children() { + return StmtRange(&Condition, &Condition + 1); + } +}; + /// \brief This represents 'default' clause in the '#pragma omp ...' directive. /// /// \code diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index d37cef8db2..2cde0c2071 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -855,6 +855,8 @@ def err_omp_unexpected_directive : Error < "unexpected OpenMP directive '#pragma omp %0'">; def err_omp_expected_punc : Error < "expected ',' or ')' in '%0' clause">; +def err_omp_expected_rparen : Error < + "expected ')' in '%0' clause">; def err_omp_unexpected_clause : Error < "unexpected OpenMP clause '%0' in directive '#pragma omp %1'">; def err_omp_more_one_clause : Error < diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index 6d1a7b27b7..529bf1b384 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -31,12 +31,14 @@ OPENMP_DIRECTIVE(parallel) OPENMP_DIRECTIVE(task) // OpenMP clauses. +OPENMP_CLAUSE(if, OMPIfClause) OPENMP_CLAUSE(default, OMPDefaultClause) OPENMP_CLAUSE(private, OMPPrivateClause) OPENMP_CLAUSE(firstprivate, OMPFirstprivateClause) OPENMP_CLAUSE(shared, OMPSharedClause) // Clauses allowed for OpenMP directives. +OPENMP_PARALLEL_CLAUSE(if) OPENMP_PARALLEL_CLAUSE(default) OPENMP_PARALLEL_CLAUSE(private) OPENMP_PARALLEL_CLAUSE(firstprivate) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 472e03cd75..df3cc596f4 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7125,6 +7125,16 @@ public: SourceLocation StartLoc, SourceLocation EndLoc); + OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, + Expr *Expr, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc); + /// \brief Called on well-formed 'if' clause. + OMPClause *ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc); + OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index f008a12075..8ed2987e6d 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -593,16 +593,24 @@ void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) { namespace { class OMPClausePrinter : public OMPClauseVisitor { raw_ostream &OS; + const PrintingPolicy &Policy; /// \brief Process clauses with list of variables. template void VisitOMPClauseList(T *Node, char StartSym); public: - OMPClausePrinter(raw_ostream &OS) : OS(OS) { } + OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy) + : OS(OS), Policy(Policy) { } #define OPENMP_CLAUSE(Name, Class) \ void Visit##Class(Class *S); #include "clang/Basic/OpenMPKinds.def" }; +void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { + OS << "if("; + Node->getCondition()->printPretty(OS, 0, Policy, 0); + OS << ")"; +} + void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { OS << "default(" << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind()) @@ -651,7 +659,7 @@ void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) { Indent() << "#pragma omp parallel "; - OMPClausePrinter Printer(OS); + OMPClausePrinter Printer(OS, Policy); ArrayRef Clauses = Node->clauses(); for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end(); I != E; ++I) diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index f1996e3882..ae3b360078 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -265,6 +265,11 @@ public: #include "clang/Basic/OpenMPKinds.def" }; +void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) { + if (C->getCondition()) + Profiler->VisitStmt(C->getCondition()); +} + void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { } template diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index 1350934d0e..4e0ab1298b 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -77,6 +77,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, .Default(OMPC_DEFAULT_unknown); case OMPC_unknown: case OMPC_threadprivate: + case OMPC_if: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: @@ -100,6 +101,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, llvm_unreachable("Invalid OpenMP 'default' clause type"); case OMPC_unknown: case OMPC_threadprivate: + case OMPC_if: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 9053407a5f..b3c7cb597e 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -269,10 +269,20 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, } switch (CKind) { + case OMPC_if: + // OpenMP [2.5, Restrictions] + // At most one if clause can appear on the directive. + if (!FirstClause) { + Diag(Tok, diag::err_omp_more_one_clause) + << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); + } + + Clause = ParseOpenMPSingleExprClause(CKind); + break; case OMPC_default: - // OpenMP [2.9.3.1, Restrictions] - // Only a single default clause may be specified on a parallel or task - // directive. + // OpenMP [2.14.3.1, Restrictions] + // Only a single default clause may be specified on a parallel, task or + // teams directive. if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); @@ -300,6 +310,39 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, return ErrorFound ? 0 : Clause; } +/// \brief Parsing of OpenMP clauses with single expressions like 'if', +/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or +/// 'thread_limit'. +/// +/// if-clause: +/// 'if' '(' expression ')' +/// +OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { + SourceLocation Loc = ConsumeToken(); + + BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); + if (T.expectAndConsume(diag::err_expected_lparen_after, + getOpenMPClauseName(Kind))) + return 0; + + ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); + ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); + + if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && + Tok.isNot(tok::annot_pragma_openmp_end)) + ConsumeAnyToken(); + + // Parse ')'. + T.consumeClose(); + + if (Val.isInvalid()) + return 0; + + return Actions.ActOnOpenMPSingleExprClause(Kind, Val.take(), Loc, + T.getOpenLocation(), + T.getCloseLocation()); +} + /// \brief Parsing of simple OpenMP clauses like 'default'. /// /// default-clause: diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 0ca7d56744..fee9b1d2ce 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -721,6 +721,48 @@ StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef Clauses, Clauses, AStmt)); } +OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, + Expr *Expr, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + OMPClause *Res = 0; + switch (Kind) { + case OMPC_if: + Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); + break; + case OMPC_default: + case OMPC_private: + case OMPC_firstprivate: + case OMPC_shared: + case OMPC_threadprivate: + case OMPC_unknown: + case NUM_OPENMP_CLAUSES: + llvm_unreachable("Clause is not allowed."); + } + return Res; +} + +OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + Expr *ValExpr = Condition; + if (!Condition->isValueDependent() && !Condition->isTypeDependent() && + !Condition->isInstantiationDependent() && + !Condition->containsUnexpandedParameterPack()) { + ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), + Condition->getExprLoc(), + Condition); + if (Val.isInvalid()) + return 0; + + ValExpr = Val.take(); + } + + return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, @@ -734,6 +776,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, ActOnOpenMPDefaultClause(static_cast(Argument), ArgumentLoc, StartLoc, LParenLoc, EndLoc); break; + case OMPC_if: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: @@ -780,7 +823,9 @@ OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, case OMPC_DEFAULT_shared: DSAStack->setDefaultDSAShared(); break; - default: + case OMPC_DEFAULT_unknown: + case NUM_OPENMP_DEFAULT_KINDS: + llvm_unreachable("Clause kind is not allowed."); break; } return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, @@ -803,6 +848,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind, case OMPC_shared: Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); break; + case OMPC_if: case OMPC_default: case OMPC_threadprivate: case OMPC_unknown: diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 7afed1a448..d9ed6f5f02 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1298,6 +1298,18 @@ public: StartLoc, EndLoc); } + /// \brief Build a new OpenMP 'if' clause. + /// + /// By default, performs semantic analysis to build the new statement. + /// Subclasses may override this routine to provide different behavior. + OMPClause *RebuildOMPIfClause(Expr *Condition, + SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + return getSema().ActOnOpenMPIfClause(Condition, StartLoc, + LParenLoc, EndLoc); + } + /// \brief Build a new OpenMP 'default' clause. /// /// By default, performs semantic analysis to build the new statement. @@ -6277,6 +6289,13 @@ TreeTransform::TransformOMPParallelDirective(OMPParallelDirective *D) { return Res; } +template +OMPClause * +TreeTransform::TransformOMPIfClause(OMPIfClause *C) { + return getDerived().RebuildOMPIfClause(C->getCondition(), C->getLocStart(), + C->getLParenLoc(), C->getLocEnd()); +} + template OMPClause * TreeTransform::TransformOMPDefaultClause(OMPDefaultClause *C) { diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 5d2f38d952..e1ca51fcc1 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1673,6 +1673,9 @@ public: OMPClause *OMPClauseReader::readClause() { OMPClause *C; switch (Record[Idx++]) { + case OMPC_if: + C = new (Context) OMPIfClause(); + break; case OMPC_default: C = new (Context) OMPDefaultClause(); break; @@ -1693,6 +1696,11 @@ OMPClause *OMPClauseReader::readClause() { return C; } +void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) { + C->setCondition(Reader->Reader.ReadSubExpr()); + C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); +} + void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) { C->setDefaultKind( static_cast(Record[Idx++])); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 77c7296f2d..428881bb69 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1679,6 +1679,11 @@ void OMPClauseWriter::writeClause(OMPClause *C) { Writer->Writer.AddSourceLocation(C->getLocEnd(), Record); } +void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) { + Writer->Writer.AddStmt(C->getCondition()); + Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); +} + void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { Record.push_back(C->getDefaultKind()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); diff --git a/test/OpenMP/parallel_ast_print.cpp b/test/OpenMP/parallel_ast_print.cpp index f2fd2f7b69..c197031c59 100644 --- a/test/OpenMP/parallel_ast_print.cpp +++ b/test/OpenMP/parallel_ast_print.cpp @@ -15,7 +15,7 @@ T tmain(T argc, T *argv) { static T a; #pragma omp parallel a=2; -#pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) +#pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (argc > 0) foo(); return 0; } @@ -24,21 +24,21 @@ T tmain(T argc, T *argv) { // CHECK-NEXT: static int a; // CHECK-NEXT: #pragma omp parallel // CHECK-NEXT: a = 2; -// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) +// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) // CHECK-NEXT: foo() // CHECK: template float tmain(float argc, float *argv) { // CHECK-NEXT: float b = argc, c, d, e, f, g; // CHECK-NEXT: static float a; // CHECK-NEXT: #pragma omp parallel // CHECK-NEXT: a = 2; -// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) +// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) // CHECK-NEXT: foo() // CHECK: template T tmain(T argc, T *argv) { // CHECK-NEXT: T b = argc, c, d, e, f, g; // CHECK-NEXT: static T a; // CHECK-NEXT: #pragma omp parallel // CHECK-NEXT: a = 2; -// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) +// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) // CHECK-NEXT: foo() int main (int argc, char **argv) { @@ -50,8 +50,8 @@ int main (int argc, char **argv) { // CHECK-NEXT: #pragma omp parallel a=2; // CHECK-NEXT: a = 2; -#pragma omp parallel default(none), private(argc,b) firstprivate(argv) -// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) +#pragma omp parallel default(none), private(argc,b) firstprivate(argv) if (argc > 0) +// CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) if(argc > 0) foo(); // CHECK-NEXT: foo(); return tmain(b, &b) + tmain(x, &x); diff --git a/test/OpenMP/parallel_if_messages.cpp b/test/OpenMP/parallel_if_messages.cpp new file mode 100644 index 0000000000..eb4180d7f5 --- /dev/null +++ b/test/OpenMP/parallel_if_messages.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} + +template // expected-note {{declared here}} +int tmain(T argc, S **argv) { + #pragma omp parallel if // expected-error {{expected '(' after 'if'}} + #pragma omp parallel if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if () // expected-error {{expected expression}} + #pragma omp parallel if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}} + #pragma omp parallel if (argc > 0 ? argv[1] : argv[2]) + #pragma omp parallel if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel' cannot contain more than one 'if' clause}} + #pragma omp parallel if (S) // expected-error {{'S' does not refer to a value}} + #pragma omp parallel if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if(argc) + foo(); + + return 0; +} + +int main(int argc, char **argv) { + #pragma omp parallel if // expected-error {{expected '(' after 'if'}} + #pragma omp parallel if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if () // expected-error {{expected expression}} + #pragma omp parallel if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}} + #pragma omp parallel if (argc > 0 ? argv[1] : argv[2]) + #pragma omp parallel if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel' cannot contain more than one 'if' clause}} + #pragma omp parallel if (S1) // expected-error {{'S1' does not refer to a value}} + #pragma omp parallel if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + #pragma omp parallel if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + + return tmain(argc, argv); +} diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index d8cca44a0e..63acd0abd5 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1939,6 +1939,10 @@ public: #include "clang/Basic/OpenMPKinds.def" }; +void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) { + Visitor->AddStmt(C->getCondition()); +} + void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { } template -- 2.40.0