r209660 - Parsing/Sema for OMPCollapseClause.
Alexander Musman
alexander.musman at gmail.com
Tue May 27 08:12:19 PDT 2014
Author: amusman
Date: Tue May 27 10:12:19 2014
New Revision: 209660
URL: http://llvm.org/viewvc/llvm-project?rev=209660&view=rev
Log:
Parsing/Sema for OMPCollapseClause.
Actual usage in Sema for collapsing loops will in some future patch.
Added:
cfe/trunk/test/OpenMP/simd_collapse_messages.cpp
Modified:
cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/simd_ast_print.cpp
cfe/trunk/test/OpenMP/simd_misc_messages.c
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Tue May 27 10:12:19 2014
@@ -2316,6 +2316,13 @@ bool RecursiveASTVisitor<Derived>::Visit
}
template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
+ TraverseStmt(C->getNumForLoops());
+ return true;
+}
+
+template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *C) {
return true;
}
Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Tue May 27 10:12:19 2014
@@ -306,6 +306,62 @@ public:
StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
};
+/// \brief This represents 'collapse' clause in the '#pragma omp ...'
+/// directive.
+///
+/// \code
+/// #pragma omp simd collapse(3)
+/// \endcode
+/// In this example directive '#pragma omp simd' has clause 'collapse'
+/// with single expression '3'.
+/// The parameter must be a constant positive integer expression, it specifies
+/// the number of nested loops that should be collapsed into a single iteration
+/// space.
+///
+class OMPCollapseClause : public OMPClause {
+ friend class OMPClauseReader;
+ /// \brief Location of '('.
+ SourceLocation LParenLoc;
+ /// \brief Number of for-loops.
+ Stmt *NumForLoops;
+
+ /// \brief Set the number of associated for-loops.
+ void setNumForLoops(Expr *Num) { NumForLoops = Num; }
+
+public:
+ /// \brief Build 'collapse' clause.
+ ///
+ /// \param Num Expression associated with this clause.
+ /// \param StartLoc Starting location of the clause.
+ /// \param LParenLoc Location of '('.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
+ NumForLoops(Num) {}
+
+ /// \brief Build an empty clause.
+ ///
+ explicit OMPCollapseClause()
+ : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
+ LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
+
+ /// \brief Sets the location of '('.
+ void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+ /// \brief Returns the location of '('.
+ SourceLocation getLParenLoc() const { return LParenLoc; }
+
+ /// \brief Return the number of associated for-loops.
+ Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_collapse;
+ }
+
+ StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
+};
+
/// \brief This represents 'default' clause in the '#pragma omp ...' directive.
///
/// \code
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue May 27 10:12:19 2014
@@ -2331,13 +2331,19 @@ RecursiveASTVisitor<Derived>::VisitOMPNu
return true;
}
-template <typename Derived>
+template<typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
TraverseStmt(C->getSafelen());
return true;
}
template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
+ TraverseStmt(C->getNumForLoops());
+ return true;
+}
+
+template<typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *C) {
return true;
}
Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Tue May 27 10:12:19 2014
@@ -41,6 +41,7 @@ OPENMP_DIRECTIVE(simd)
OPENMP_CLAUSE(if, OMPIfClause)
OPENMP_CLAUSE(num_threads, OMPNumThreadsClause)
OPENMP_CLAUSE(safelen, OMPSafelenClause)
+OPENMP_CLAUSE(collapse, OMPCollapseClause)
OPENMP_CLAUSE(default, OMPDefaultClause)
OPENMP_CLAUSE(private, OMPPrivateClause)
OPENMP_CLAUSE(firstprivate, OMPFirstprivateClause)
@@ -63,6 +64,7 @@ OPENMP_PARALLEL_CLAUSE(copyin)
OPENMP_SIMD_CLAUSE(private)
OPENMP_SIMD_CLAUSE(linear)
OPENMP_SIMD_CLAUSE(safelen)
+OPENMP_SIMD_CLAUSE(collapse)
// Static attributes for 'default' clause.
OPENMP_DEFAULT_KIND(none)
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue May 27 10:12:19 2014
@@ -7334,6 +7334,10 @@ public:
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed 'collapse' clause.
+ OMPClause *ActOnOpenMPCollapseClause(Expr *Num, SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc);
OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
unsigned Argument,
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Tue May 27 10:12:19 2014
@@ -608,6 +608,12 @@ void OMPClausePrinter::VisitOMPSafelenCl
OS << ")";
}
+void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
+ OS << "collapse(";
+ Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
+ OS << ")";
+}
+
void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
OS << "default("
<< getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind())
Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Tue May 27 10:12:19 2014
@@ -279,6 +279,11 @@ void OMPClauseProfiler::VisitOMPSafelenC
Profiler->VisitStmt(C->getSafelen());
}
+void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
+ if (C->getNumForLoops())
+ Profiler->VisitStmt(C->getNumForLoops());
+}
+
void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Tue May 27 10:12:19 2014
@@ -83,6 +83,7 @@ unsigned clang::getOpenMPSimpleClauseTyp
case OMPC_if:
case OMPC_num_threads:
case OMPC_safelen:
+ case OMPC_collapse:
case OMPC_private:
case OMPC_firstprivate:
case OMPC_shared:
@@ -119,6 +120,7 @@ const char *clang::getOpenMPSimpleClause
case OMPC_if:
case OMPC_num_threads:
case OMPC_safelen:
+ case OMPC_collapse:
case OMPC_private:
case OMPC_firstprivate:
case OMPC_shared:
Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Tue May 27 10:12:19 2014
@@ -257,7 +257,8 @@ bool Parser::ParseOpenMPSimpleVarList(Op
///
/// clause:
/// if-clause | num_threads-clause | safelen-clause | default-clause |
-/// private-clause | firstprivate-clause | shared-clause | linear-clause
+/// private-clause | firstprivate-clause | shared-clause | linear-clause |
+/// collapse-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
@@ -274,11 +275,13 @@ OMPClause *Parser::ParseOpenMPClause(Ope
case OMPC_if:
case OMPC_num_threads:
case OMPC_safelen:
+ case OMPC_collapse:
// OpenMP [2.5, Restrictions]
// At most one if clause can appear on the directive.
// At most one num_threads clause can appear on the directive.
// OpenMP [2.8.1, simd construct, Restrictions]
- // Only one safelen clause can appear on a simd directive.
+ // Only one safelen clause can appear on a simd directive.
+ // Only one collapse clause can appear on a simd directive.
if (!FirstClause) {
Diag(Tok, diag::err_omp_more_one_clause)
<< getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind);
@@ -334,6 +337,9 @@ OMPClause *Parser::ParseOpenMPClause(Ope
/// safelen-clause:
/// 'safelen' '(' expression ')'
///
+/// collapse-clause:
+/// 'collapse' '(' expression ')'
+///
OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
SourceLocation Loc = ConsumeToken();
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue May 27 10:12:19 2014
@@ -809,6 +809,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprCl
case OMPC_safelen:
Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc);
break;
+ case OMPC_collapse:
+ Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc);
+ break;
case OMPC_default:
case OMPC_proc_bind:
case OMPC_private:
@@ -950,6 +953,20 @@ OMPClause *Sema::ActOnOpenMPSafelenClaus
OMPSafelenClause(Safelen.take(), StartLoc, LParenLoc, EndLoc);
}
+OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *Num, SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc) {
+ // OpenMP [2.8.1, simd construct, Description]
+ // The parameter of the collapse clause must be a constant
+ // positive integer expression.
+ ExprResult NumForLoops =
+ VerifyPositiveIntegerConstantInClause(Num, OMPC_collapse);
+ if (NumForLoops.isInvalid())
+ return nullptr;
+ return new (Context)
+ OMPCollapseClause(NumForLoops.take(), StartLoc, LParenLoc, EndLoc);
+}
+
OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
unsigned Argument,
SourceLocation ArgumentLoc,
@@ -971,6 +988,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause
case OMPC_if:
case OMPC_num_threads:
case OMPC_safelen:
+ case OMPC_collapse:
case OMPC_private:
case OMPC_firstprivate:
case OMPC_shared:
@@ -1086,6 +1104,7 @@ OMPClause *Sema::ActOnOpenMPVarListClaus
case OMPC_if:
case OMPC_num_threads:
case OMPC_safelen:
+ case OMPC_collapse:
case OMPC_default:
case OMPC_proc_bind:
case OMPC_threadprivate:
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue May 27 10:12:19 2014
@@ -1333,6 +1333,17 @@ public:
return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
}
+ /// \brief Build a new OpenMP 'collapse' clause.
+ ///
+ /// By default, performs semantic analysis to build the new statement.
+ /// Subclasses may override this routine to provide different behavior.
+ OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc) {
+ return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
+ EndLoc);
+ }
+
/// \brief Build a new OpenMP 'default' clause.
///
/// By default, performs semantic analysis to build the new statement.
@@ -6399,6 +6410,16 @@ TreeTransform<Derived>::TransformOMPSafe
E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
}
+template <typename Derived>
+OMPClause *
+TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
+ ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
+ if (E.isInvalid())
+ return 0;
+ return getDerived().RebuildOMPCollapseClause(
+ E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
+}
+
template<typename Derived>
OMPClause *
TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue May 27 10:12:19 2014
@@ -1682,6 +1682,9 @@ OMPClause *OMPClauseReader::readClause()
case OMPC_safelen:
C = new (Context) OMPSafelenClause();
break;
+ case OMPC_collapse:
+ C = new (Context) OMPCollapseClause();
+ break;
case OMPC_default:
C = new (Context) OMPDefaultClause();
break;
@@ -1726,6 +1729,11 @@ void OMPClauseReader::VisitOMPSafelenCla
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
}
+void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) {
+ C->setNumForLoops(Reader->Reader.ReadSubExpr());
+ C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
+}
+
void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
C->setDefaultKind(
static_cast<OpenMPDefaultClauseKind>(Record[Idx++]));
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Tue May 27 10:12:19 2014
@@ -1690,6 +1690,11 @@ void OMPClauseWriter::VisitOMPSafelenCla
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
}
+void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) {
+ Writer->Writer.AddStmt(C->getNumForLoops());
+ Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
+}
+
void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) {
Record.push_back(C->getDefaultKind());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
Modified: cfe/trunk/test/OpenMP/simd_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_ast_print.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/simd_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/simd_ast_print.cpp Tue May 27 10:12:19 2014
@@ -97,10 +97,10 @@ int main (int argc, char **argv) {
for (int i=0; i < 2; ++i)*a=2;
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: *a = 2;
-#pragma omp simd private(argc, b)
+#pragma omp simd private(argc, b) collapse(2)
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j) {foo(); k1 += 8; k2 += 8;}
-// CHECK-NEXT: #pragma omp simd private(argc,b)
+// CHECK-NEXT: #pragma omp simd private(argc,b) collapse(2)
// CHECK-NEXT: for (int i = 0; i < 10; ++i)
// CHECK-NEXT: for (int j = 0; j < 10; ++j) {
// CHECK-NEXT: foo();
@@ -112,8 +112,8 @@ int main (int argc, char **argv) {
// CHECK-NEXT: foo();
const int CLEN = 4;
// CHECK-NEXT: const int CLEN = 4;
- #pragma omp simd linear(a:CLEN) safelen(CLEN)
-// CHECK-NEXT: #pragma omp simd linear(a: CLEN) safelen(CLEN)
+ #pragma omp simd linear(a:CLEN) safelen(CLEN) collapse( 1 )
+// CHECK-NEXT: #pragma omp simd linear(a: CLEN) safelen(CLEN) collapse(1)
for (int i = 0; i < 10; ++i)foo();
// CHECK-NEXT: for (int i = 0; i < 10; ++i)
// CHECK-NEXT: foo();
Added: cfe/trunk/test/OpenMP/simd_collapse_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_collapse_messages.cpp?rev=209660&view=auto
==============================================================================
--- cfe/trunk/test/OpenMP/simd_collapse_messages.cpp (added)
+++ cfe/trunk/test/OpenMP/simd_collapse_messages.cpp Tue May 27 10:12:19 2014
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+ return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, typename S, int N, int ST> // expected-note {{declared here}}
+T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
+ #pragma omp simd collapse // expected-error {{expected '(' after 'collapse'}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse () // expected-error {{expected expression}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ // expected-error at +3 {{expected ')'}} expected-note at +3 {{to match this '('}}
+ // expected-error at +2 2 {{expression is not an integral constant expression}}
+ // expected-note at +1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}}
+ #pragma omp simd collapse (argc
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ // expected-error at +1 2 {{argument to 'collapse' clause must be a positive integer value}}
+ #pragma omp simd collapse (ST // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse (1)) // expected-warning {{extra tokens at the end of '#pragma omp simd' are ignored}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse ((ST > 0) ? 1 + ST : 2)
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ // expected-error at +3 2 {{directive '#pragma omp simd' cannot contain more than one 'collapse' clause}}
+ // expected-error at +2 2 {{argument to 'collapse' clause must be a positive integer value}}
+ // expected-error at +1 2 {{expression is not an integral constant expression}}
+ #pragma omp simd collapse (foobool(argc)), collapse (true), collapse (-5)
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse (S) // expected-error {{'S' does not refer to a value}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ // expected-error at +1 2 {{expression is not an integral constant expression}}
+ #pragma omp simd collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse (1)
+ for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ #pragma omp simd collapse (N) // expected-error {{argument to 'collapse' clause must be a positive integer value}}
+ for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
+ return argc;
+}
+
+int main(int argc, char **argv) {
+ #pragma omp simd collapse // expected-error {{expected '(' after 'collapse'}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse () // expected-error {{expected expression}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse (4 // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse (2+2)) // expected-warning {{extra tokens at the end of '#pragma omp simd' are ignored}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse (foobool(1) > 0 ? 1 : 2) // expected-error {{expression is not an integral constant expression}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ // expected-error at +3 {{expression is not an integral constant expression}}
+ // expected-error at +2 2 {{directive '#pragma omp simd' cannot contain more than one 'collapse' clause}}
+ // expected-error at +1 2 {{argument to 'collapse' clause must be a positive integer value}}
+ #pragma omp simd collapse (foobool(argc)), collapse (true), collapse (-5)
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ #pragma omp simd collapse (S1) // expected-error {{'S1' does not refer to a value}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ // expected-error at +1 {{expression is not an integral constant expression}}
+ #pragma omp simd collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
+ // expected-error at +3 {{statement after '#pragma omp simd' must be a for loop}}
+ // expected-note at +1 {{in instantiation of function template specialization 'tmain<int, char, -1, -2>' requested here}}
+ #pragma omp simd collapse(collapse(tmain<int, char, -1, -2>(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
+ foo();
+ // expected-note at +1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
+ return tmain<int, char, 1, 0>(argc, argv);
+}
+
Modified: cfe/trunk/test/OpenMP/simd_misc_messages.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_misc_messages.c?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/simd_misc_messages.c (original)
+++ cfe/trunk/test/OpenMP/simd_misc_messages.c Tue May 27 10:12:19 2014
@@ -146,6 +146,78 @@ void test_safelen()
for (i = 0; i < 16; ++i);
}
+void test_collapse()
+{
+ int i;
+ // expected-error at +1 {{expected '('}}
+ #pragma omp simd collapse
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +1 {{expected expression}} expected-error at +1 {{expected ')'}} expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +1 {{expected expression}}
+ #pragma omp simd collapse()
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +1 {{expected expression}} expected-error at +1 {{expected ')'}} expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(,
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +1 {{expected expression}} expected-error at +1 {{expected ')'}} expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(,)
+ for (i = 0; i < 16; ++i) ;
+ // expected-warning at +2 {{extra tokens at the end of '#pragma omp simd' are ignored}}
+ // expected-error at +1 {{expected '('}}
+ #pragma omp simd collapse 4)
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4,
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4,)
+ for (i = 0; i < 16; ++i) ;
+ // xxpected-error at +1 {{expected expression}}
+ #pragma omp simd collapse(4)
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4 4)
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4,,4)
+ for (i = 0; i < 16; ++i) ;
+ #pragma omp simd collapse(4)
+ for (int i1 = 0; i1 < 16; ++i1)
+ for (int i2 = 0; i2 < 16; ++i2)
+ for (int i3 = 0; i3 < 16; ++i3)
+ for (int i4 = 0; i4 < 16; ++i4)
+ foo();
+ // expected-error at +2 {{expected ')'}}
+ // expected-note at +1 {{to match this '('}}
+ #pragma omp simd collapse(4,8)
+ for (i = 0; i < 16; ++i) ;
+ // expected-error at +1 {{expression is not an integer constant expression}}
+ #pragma omp simd collapse(2.5)
+ for (i = 0; i < 16; ++i);
+ // expected-error at +1 {{expression is not an integer constant expression}}
+ #pragma omp simd collapse(foo())
+ for (i = 0; i < 16; ++i);
+ // expected-error at +1 {{argument to 'collapse' clause must be a positive integer value}}
+ #pragma omp simd collapse(-5)
+ for (i = 0; i < 16; ++i);
+ // expected-error at +1 {{argument to 'collapse' clause must be a positive integer value}}
+ #pragma omp simd collapse(0)
+ for (i = 0; i < 16; ++i);
+ // expected-error at +1 {{argument to 'collapse' clause must be a positive integer value}}
+ #pragma omp simd collapse(5-5)
+ for (i = 0; i < 16; ++i);
+}
+
void test_linear()
{
int i;
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=209660&r1=209659&r2=209660&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue May 27 10:12:19 2014
@@ -1935,6 +1935,10 @@ void OMPClauseEnqueue::VisitOMPSafelenCl
Visitor->AddStmt(C->getSafelen());
}
+void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) {
+ Visitor->AddStmt(C->getNumForLoops());
+}
+
void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
More information about the cfe-commits
mailing list