diff --git a/clang-tools-extra/docs/clang-tidy/checks/openmp-use-default-none.rst b/clang-tools-extra/docs/clang-tidy/checks/openmp-use-default-none.rst --- a/clang-tools-extra/docs/clang-tidy/checks/openmp-use-default-none.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/openmp-use-default-none.rst @@ -51,3 +51,12 @@ // WARNING: OpenMP directive ``parallel`` specifies ``default(shared)`` // clause. Consider using ``default(none)`` clause instead. } + + // ``parallel`` directive can have ``default`` clause, and said clause is + // specified, but with ``shared`` kind, which is not ``none``, diagnose. + void p0_3() { + #pragma omp parallel default(firstprivate) + ; + // WARNING: OpenMP directive ``parallel`` specifies ``default(firstprivate)`` + // clause. Consider using ``default(none)`` clause instead. + } diff --git a/clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp b/clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/openmp-use-default-none.cpp @@ -42,6 +42,15 @@ // CHECK-NOTES: :[[@LINE-3]]:22: note: existing 'default' clause specified here } +// 'parallel' directive can have 'default' clause, and said clause specified, +// but with 'firstprivate' kind, which is not 'none', diagnose. +void p0_3() { +#pragma omp parallel default(firstprivate) + ; + // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'parallel' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead + // CHECK-NOTES: :[[@LINE-3]]:22: note: existing 'default' clause specified here +} + // 'task' directive. // 'task' directive can have 'default' clause, but said clause is not @@ -68,6 +77,15 @@ // CHECK-NOTES: :[[@LINE-3]]:18: note: existing 'default' clause specified here } +// 'task' directive can have 'default' clause, and said clause specified, +// but with 'firstprivate' kind, which is not 'none', diagnose. +void p1_3() { +#pragma omp task default(firstprivate) + ; + // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'task' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead + // CHECK-NOTES: :[[@LINE-3]]:18: note: existing 'default' clause specified here +} + // 'teams' directive. (has to be inside of 'target' directive) // 'teams' directive can have 'default' clause, but said clause is not @@ -97,6 +115,16 @@ // CHECK-NOTES: :[[@LINE-3]]:19: note: existing 'default' clause specified here } +// 'teams' directive can have 'default' clause, and said clause specified, +// but with 'firstprivate' kind, which is not 'none', diagnose. +void p2_3() { +#pragma omp target +#pragma omp teams default(firstprivate) + ; + // CHECK-NOTES: :[[@LINE-2]]:1: warning: OpenMP directive 'teams' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead + // CHECK-NOTES: :[[@LINE-3]]:19: note: existing 'default' clause specified here +} + // 'taskloop' directive. // 'taskloop' directive can have 'default' clause, but said clause is not @@ -126,6 +154,16 @@ // CHECK-NOTES: :[[@LINE-4]]:22: note: existing 'default' clause specified here } +// 'taskloop' directive can have 'default' clause, and said clause specified, +// but with 'firstprivate' kind, which is not 'none', diagnose. +void p3_3(const int a) { +#pragma omp taskloop default(firstprivate) + for (int b = 0; b < a; b++) + ; + // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'taskloop' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead + // CHECK-NOTES: :[[@LINE-4]]:22: note: existing 'default' clause specified here +} + //----------------------------------------------------------------------------// // Combined directives. // Let's not test every single possible permutation/combination of directives, @@ -158,3 +196,13 @@ // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' specifies 'default(shared)' clause, consider using 'default(none)' clause instead // CHECK-NOTES: :[[@LINE-4]]:26: note: existing 'default' clause specified here } + +// 'parallel' directive can have 'default' clause, and said clause specified, +// but with 'firstprivate' kind, which is not 'none', diagnose. +void p4_3(const int a) { +#pragma omp parallel for default(firstprivate) + for (int b = 0; b < a; b++) + ; + // CHECK-NOTES: :[[@LINE-3]]:1: warning: OpenMP directive 'parallel for' specifies 'default(firstprivate)' clause, consider using 'default(none)' clause instead + // CHECK-NOTES: :[[@LINE-4]]:26: note: existing 'default' clause specified here +} diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -676,9 +676,10 @@ #pragma omp parallel default(none) #pragma omp parallel default(shared) + #pragma omp parallel default(firstprivate) #pragma omp parallel -``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``. +``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``, and ``default(firstprivate)``. @@ -3634,6 +3635,7 @@ #pragma omp parallel #pragma omp parallel default(none) #pragma omp parallel default(shared) + #pragma omp parallel default(firstprivate) ``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. @@ -3647,11 +3649,26 @@ #pragma omp parallel #pragma omp parallel default(none) #pragma omp parallel default(shared) + #pragma omp parallel default(firstprivate) ``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. +
Matches if the OpenMP ``default`` clause has ``firstprivate`` kind specified. + +Given + + #pragma omp parallel + #pragma omp parallel default(none) + #pragma omp parallel default(shared) + #pragma omp parallel default(firstprivate) + +``ompDefaultClause(isFirstPrivateKind())`` matches only ``default(firstprivate)``. +
Matches if the OpenMP directive is allowed to contain the specified OpenMP clause kind. diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -7043,10 +7043,12 @@ /// \code /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) +/// #pragma omp parallel default(firstprivate) /// #pragma omp parallel /// \endcode /// -/// ``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``. +/// ``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``, and +/// ``default(firstprivate)`` extern const internal::VariadicDynCastAllOfMatcherompDefaultClause; @@ -7058,6 +7060,7 @@ /// #pragma omp parallel /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) +/// #pragma omp parallel default(firstprivate) /// \endcode /// /// ``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. @@ -7073,6 +7076,7 @@ /// #pragma omp parallel /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) +/// #pragma omp parallel default(firstprivate) /// \endcode /// /// ``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. @@ -7080,6 +7084,24 @@ return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_shared; } +/// Matches if the OpenMP ``default`` clause has ``firstprivate`` kind +/// specified. +/// +/// Given +/// +/// \code +/// #pragma omp parallel +/// #pragma omp parallel default(none) +/// #pragma omp parallel default(shared) +/// #pragma omp parallel default(firstprivate) +/// \endcode +/// +/// ``ompDefaultClause(isFirstPrivateKind())`` matches only +/// ``default(firstprivate)``. +AST_MATCHER(OMPDefaultClause, isFirstPrivateKind) { + return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_firstprivate; +} + /// Matches if the OpenMP directive is allowed to contain the specified OpenMP /// clause kind. /// diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10122,6 +10122,8 @@ def err_omp_non_lvalue_in_map_or_motion_clauses: Error< "expected addressable lvalue in '%0' clause" >; +def err_omp_invalid_dsa: Error< + "data-sharing attribute '%0' in '%1' clause requires OpenMP version %2 or above">; } // end of OpenMP category let CategoryName = "Related Result Type Issue" in { diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -377,6 +377,7 @@ REGISTER_MATCHER(isExpr); REGISTER_MATCHER(isExternC); REGISTER_MATCHER(isFinal); + REGISTER_MATCHER(isFirstPrivateKind); REGISTER_MATCHER(isImplicit); REGISTER_MATCHER(isInStdNamespace); REGISTER_MATCHER(isInTemplateInstantiation); diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -1391,7 +1391,7 @@ /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. /// /// default-clause: -/// 'default' '(' 'none' | 'shared' ') +/// 'default' '(' 'none' | 'shared' | 'firstprivate' ') /// /// proc_bind-clause: /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') @@ -2603,7 +2603,7 @@ /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. /// /// default-clause: -/// 'default' '(' 'none' | 'shared' ')' +/// 'default' '(' 'none' | 'shared' | 'firstprivate' ')' /// /// proc_bind-clause: /// 'proc_bind' '(' 'master' | 'close' | 'spread' ')' diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -49,9 +49,10 @@ namespace { /// Default data sharing attributes, which can be applied to directive. enum DefaultDataSharingAttributes { - DSA_unspecified = 0, /// Data sharing attribute not specified. - DSA_none = 1 << 0, /// Default data sharing attribute 'none'. - DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'. + DSA_unspecified = 0, /// Data sharing attribute not specified. + DSA_none = 1 << 0, /// Default data sharing attribute 'none'. + DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'. + DSA_firstprivate = 1 << 2, /// Default data sharing attribute 'firstprivate'. }; /// Stack for tracking declarations used in OpenMP directives and @@ -624,6 +625,11 @@ getTopOfStack().DefaultAttr = DSA_shared; getTopOfStack().DefaultAttrLoc = Loc; } + /// Set default data sharing attribute to firstprivate. + void setDefaultDSAFirstPrivate(SourceLocation Loc) { + getTopOfStack().DefaultAttr = DSA_firstprivate; + getTopOfStack().DefaultAttrLoc = Loc; + } /// Set default data mapping attribute to Modifier:Kind void setDefaultDMAAttr(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, @@ -1046,6 +1052,11 @@ return DVar; case DSA_none: return DVar; + case DSA_firstprivate: + DVar.RefExpr = nullptr; + DVar.CKind = OMPC_firstprivate; + DVar.PrivateCopy = nullptr; + return DVar; case DSA_unspecified: // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, implicitly determined, p.2] @@ -3053,6 +3064,26 @@ return; } + // The default(firstprivate) clause requires that each variable that has + // static storage duration and is of global or namespace scope must have + // its data-sharing attribute explicitly determined by being listed in a + // data-sharing attribute clause. + VarDecl *CanonicalVD = VD->getCanonicalDecl(); + if (Stack->getDefaultDSA() == DSA_firstprivate && + VD->getStorageClass() == SC_Static && + (CanonicalVD->getDeclContext()->isNamespace() || + !VD->isLocalVarDeclOrParm())) { + VarsWithInheritedDSA[VD] = E; + return; + } + + // Create implicit firstprivate variables as necessary under + // default(firstprivate). + if (Stack->getDefaultDSA() == DSA_firstprivate) { + ImplicitFirstprivate.emplace_back(E); + return; + } + // OpenMP 5.0 [2.19.7.2, defaultmap clause, Description] // If implicit-behavior is none, each variable referenced in the // construct that does not have a predetermined data-sharing attribute @@ -4965,8 +4996,10 @@ ErrorFound = Res.isInvalid() || ErrorFound; - // Check variables in the clauses if default(none) was specified. - if (DSAStack->getDefaultDSA() == DSA_none) { + // Check variables in the clauses if default(none) or + // default(firstprivate) was specified. + if (DSAStack->getDefaultDSA() == DSA_none || + DSAStack->getDefaultDSA() == DSA_firstprivate) { DSAAttrChecker DSAChecker(DSAStack, *this, nullptr); for (OMPClause *C : Clauses) { switch (C->getClauseKind()) { @@ -5070,7 +5103,8 @@ if (P.getFirst()->isImplicit() || isa (P.getFirst())) continue; ErrorFound = true; - if (DSAStack->getDefaultDSA() == DSA_none) { + if (DSAStack->getDefaultDSA() == DSA_none || + DSAStack->getDefaultDSA() == DSA_firstprivate) { Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) << P.first << P.second->getSourceRange(); Diag(DSAStack->getDefaultDSALocation(), diag::note_omp_default_dsa_none); @@ -12146,6 +12180,7 @@ case OMPC_destroy: llvm_unreachable("Clause is not allowed."); } + return Res; } @@ -12182,10 +12217,20 @@ << getOpenMPClauseName(OMPC_default); return nullptr; } + + if (getLangOpts().OpenMP < 51 && Kind == OMP_DEFAULT_firstprivate) { + Diag(StartLoc, diag::err_omp_invalid_dsa) + << getOpenMPClauseName(OMPC_firstprivate) + << getOpenMPClauseName(OMPC_default) + << "5.1"; + } + if (Kind == OMP_DEFAULT_none) DSAStack->setDefaultDSANone(KindKwLoc); else if (Kind == OMP_DEFAULT_shared) DSAStack->setDefaultDSAShared(KindKwLoc); + else if (Kind == OMP_DEFAULT_firstprivate) + DSAStack->setDefaultDSAFirstPrivate(KindKwLoc); return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); diff --git a/clang/test/OpenMP/distribute_parallel_for_default_messages.cpp b/clang/test/OpenMP/distribute_parallel_for_default_messages.cpp --- a/clang/test/OpenMP/distribute_parallel_for_default_messages.cpp +++ b/clang/test/OpenMP/distribute_parallel_for_default_messages.cpp @@ -2,8 +2,15 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + template T tmain(T argc) { int i; @@ -14,12 +21,12 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp distribute parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -34,7 +41,7 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -62,12 +69,12 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp distribute parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -82,7 +89,7 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -98,5 +105,17 @@ for (i = 0; i < argc; ++i) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} foo(); +#pragma omp target +#pragma omp teams +#ifndef OMP51 +#pragma omp distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (i = 0; i < argc; ++i) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return (tmain (argc) + tmain (argv[0][0])); // expected-note {{in instantiation of function template specialization 'tmain ' requested here}} expected-note {{in instantiation of function template specialization 'tmain ' requested here}} } diff --git a/clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp b/clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp --- a/clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp +++ b/clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp @@ -14,12 +14,12 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp distribute parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -34,7 +34,7 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -62,12 +62,12 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp distribute parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target @@ -82,7 +82,7 @@ foo(); #pragma omp target #pragma omp teams -#pragma omp distribute parallel for simd default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp distribute parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target diff --git a/clang/test/OpenMP/driver.c b/clang/test/OpenMP/driver.c --- a/clang/test/OpenMP/driver.c +++ b/clang/test/OpenMP/driver.c @@ -47,6 +47,7 @@ // RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=31 | FileCheck --check-prefix=CHECK-VERSION %s // RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=40 | FileCheck --check-prefix=CHECK-VERSION %s // RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=45 | FileCheck --check-prefix=CHECK-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=51 | FileCheck --check-prefix=CHECK-VERSION %s // CHECK-VERSION-NOT: #define _OPENMP diff --git a/clang/test/OpenMP/parallel_default_messages.cpp b/clang/test/OpenMP/parallel_default_messages.cpp --- a/clang/test/OpenMP/parallel_default_messages.cpp +++ b/clang/test/OpenMP/parallel_default_messages.cpp @@ -4,18 +4,24 @@ // RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-version=40 -fopenmp -ferror-limit 100 -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-version=31 -fopenmp -ferror-limit 100 -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-version=30 -fopenmp -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-version=51 -fopenmp -DOMP51 -ferror-limit 100 -o - %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { const int c = 0; #pragma omp parallel default // expected-error {{expected '(' after 'default'}} - #pragma omp parallel default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} - #pragma omp parallel default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} - #pragma omp parallel default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} - #pragma omp parallel default (shared), default(shared) // expected-error {{directive '#pragma omp parallel' cannot contain more than one 'default' clause}} - #pragma omp parallel default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} +#pragma omp parallel default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel default(shared), default(shared) // expected-error {{directive '#pragma omp parallel' cannot contain more than one 'default' clause}} +#pragma omp parallel default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp parallel default(none) // expected-note {{explicit data sharing attribute requested here}} @@ -27,5 +33,16 @@ #pragma omp parallel default(none) // ge40-note {{explicit data sharing attribute requested here}} (void)c; // ge40-error {{variable 'c' must have explicitly specified data sharing attributes}} + +#ifndef OMP51 +#pragma omp parallel default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp parallel default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/parallel_for_default_messages.cpp b/clang/test/OpenMP/parallel_for_default_messages.cpp --- a/clang/test/OpenMP/parallel_for_default_messages.cpp +++ b/clang/test/OpenMP/parallel_for_default_messages.cpp @@ -1,18 +1,24 @@ // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -DOMP51 -ferror-limit 100 -o - %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { int i; #pragma omp parallel for default // expected-error {{expected '(' after 'default'}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp parallel for default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{explicit data sharing attribute requested here}} @@ -21,7 +27,7 @@ #pragma omp parallel for default(shared), default(shared) // expected-error {{directive '#pragma omp parallel for' cannot contain more than one 'default' clause}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); @@ -34,5 +40,15 @@ for (i = 0; i < argc; ++i) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} foo(); +#ifndef OMP51 +#pragma omp parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (i = 0; i < argc; ++i) { + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/parallel_for_simd_default_messages.cpp b/clang/test/OpenMP/parallel_for_simd_default_messages.cpp --- a/clang/test/OpenMP/parallel_for_simd_default_messages.cpp +++ b/clang/test/OpenMP/parallel_for_simd_default_messages.cpp @@ -2,17 +2,24 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { int i; #pragma omp parallel for simd default // expected-error {{expected '(' after 'default'}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for simd default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for simd default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp parallel for simd default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{explicit data sharing attribute requested here}} @@ -21,7 +28,7 @@ #pragma omp parallel for simd default(shared), default(shared) // expected-error {{directive '#pragma omp parallel for simd' cannot contain more than one 'default' clause}} for (i = 0; i < argc; ++i) foo(); -#pragma omp parallel for simd default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); @@ -34,5 +41,15 @@ for (i = 0; i < argc; ++i) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} expected-error {{variable 'i' must have explicitly specified data sharing attributes}} foo(); +#ifndef OMP51 +#pragma omp task default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp task default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (i = 0; i < argc; ++i) { + x++; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + y++; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/parallel_master_codegen.cpp b/clang/test/OpenMP/parallel_master_codegen.cpp --- a/clang/test/OpenMP/parallel_master_codegen.cpp +++ b/clang/test/OpenMP/parallel_master_codegen.cpp @@ -118,6 +118,49 @@ #endif +#ifdef CK31 +///==========================================================================/// +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK31 +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK31 + +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK31 -fopenmp-version=51 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK31-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK31-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" + +void parallel_master_private() { + int a; +#pragma omp parallel master default(firstprivate) + a++; +} + +// CK31-LABEL: define void @{{.+}}parallel_master{{.+}} +// CK31: [[A_VAL:%.+]] = alloca i32 +// CK31: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* {{.+}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void + +// CK31: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]], i32* dereferenceable(4) [[A_VAL]]) +// CK31: [[GTID_ADDR:%.+]] = alloca i32* +// CK31: [[BTID_ADDR:%.+]] = alloca i32* +// CK31: [[A_ADDR:%.+]] = alloca i32* +// CK31: [[A_VAL]]1 = alloca i32, align 4 +// CK31: store i32* [[GTID]], i32** [[GTID_ADDR]] +// CK31: store i32* [[BTID]], i32** [[BTID_ADDR]] +// CK31: store i32* [[A_VAL]], i32** [[A_ADDR]] +// CK31: [[ZERO:%.+]] = load i32*, i32** [[A_ADDR]] +// CK31: [[ONE:%.+]] = load i32, i32* [[ZERO:%.+]] +// CK31: store i32 [[ONE:%.+]], i32* [[A_VAL]]1 +// CK31: [[TWO:%.+]] = load i32*, i32** [[GTID_ADDR:%.+]] +// CK31: [[THREE:%.+]] = load i32, i32* [[TWO:%.+]] +// CK31: [[FOUR:%.+]] = call i32 @__kmpc_master(%struct.ident_t* @0, i32 [[THREE:%.+]]) +// CK31: [[FIVE:%.+]] = icmp ne i32 [[FOUR:%.+]], 0 +// CK31: br i1 [[FIVE:%.+]], label [[OMP_IF_THEN:%.+]], label [[OMP_IF_END:%.+]] + +#endif + #ifdef CK4 ///==========================================================================/// // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK4 diff --git a/clang/test/OpenMP/parallel_master_default_messages.cpp b/clang/test/OpenMP/parallel_master_default_messages.cpp --- a/clang/test/OpenMP/parallel_master_default_messages.cpp +++ b/clang/test/OpenMP/parallel_master_default_messages.cpp @@ -2,20 +2,27 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp parallel master default // expected-error {{expected '(' after 'default'}} { -#pragma omp parallel master default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel master default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} { -#pragma omp parallel master default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel master default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} { #pragma omp parallel master default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} { #pragma omp parallel master default(shared), default(shared) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'default' clause}} { -#pragma omp parallel master default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel master default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} { foo(); } @@ -37,5 +44,16 @@ ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} } } + +#ifndef OMP51 +#pragma omp parallel master default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp parallel master default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/parallel_sections_default_messages.cpp b/clang/test/OpenMP/parallel_sections_default_messages.cpp --- a/clang/test/OpenMP/parallel_sections_default_messages.cpp +++ b/clang/test/OpenMP/parallel_sections_default_messages.cpp @@ -7,15 +7,15 @@ int main(int argc, char **argv) { #pragma omp parallel sections default // expected-error {{expected '(' after 'default'}} { -#pragma omp parallel sections default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp parallel sections default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} { -#pragma omp parallel sections default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel sections default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} { #pragma omp parallel sections default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} { #pragma omp parallel sections default(shared), default(shared) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'default' clause}} { -#pragma omp parallel sections default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp parallel sections default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} { foo(); } diff --git a/clang/test/OpenMP/target_parallel_default_messages.cpp b/clang/test/OpenMP/target_parallel_default_messages.cpp --- a/clang/test/OpenMP/target_parallel_default_messages.cpp +++ b/clang/test/OpenMP/target_parallel_default_messages.cpp @@ -2,20 +2,27 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target parallel default // expected-error {{expected '(' after 'default'}} foo(); - #pragma omp target parallel default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target parallel default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} foo(); - #pragma omp target parallel default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target parallel default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} foo(); #pragma omp target parallel default (shared), default(shared) // expected-error {{directive '#pragma omp target parallel' cannot contain more than one 'default' clause}} foo(); - #pragma omp target parallel default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target parallel default(none) // expected-note {{explicit data sharing attribute requested here}} @@ -28,5 +35,16 @@ #pragma omp target parallel default(none) // expected-note {{explicit data sharing attribute requested here}} #pragma omp parallel default(shared) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + +#ifndef OMP51 +#pragma omp target parallel default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target parallel default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif +{ + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} +} + return 0; } diff --git a/clang/test/OpenMP/target_parallel_for_default_messages.cpp b/clang/test/OpenMP/target_parallel_for_default_messages.cpp --- a/clang/test/OpenMP/target_parallel_for_default_messages.cpp +++ b/clang/test/OpenMP/target_parallel_for_default_messages.cpp @@ -1,18 +1,24 @@ // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -DOMP51 -ferror-limit 100 -o - %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { int i; #pragma omp target parallel for default // expected-error {{expected '(' after 'default'}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target parallel for default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{explicit data sharing attribute requested here}} @@ -21,7 +27,7 @@ #pragma omp target parallel for default(shared), default(shared) // expected-error {{directive '#pragma omp target parallel for' cannot contain more than one 'default' clause}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); @@ -34,5 +40,15 @@ for (i = 0; i < argc; ++i) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} foo(); +#ifndef OMP51 +#pragma omp target parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (i = 0; i < argc; ++i) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp b/clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp --- a/clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp +++ b/clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp @@ -1,18 +1,24 @@ // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { int i; #pragma omp target parallel for simd default // expected-error {{expected '(' after 'default'}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for simd default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for simd default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); #pragma omp target parallel for simd default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{explicit data sharing attribute requested here}} @@ -21,7 +27,7 @@ #pragma omp target parallel for simd default(shared), default(shared) // expected-error {{directive '#pragma omp target parallel for simd' cannot contain more than one 'default' clause}} for (i = 0; i < argc; ++i) foo(); -#pragma omp target parallel for simd default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (i = 0; i < argc; ++i) foo(); @@ -34,5 +40,15 @@ for (i = 0; i < argc; ++i) // expected-error {{variable 'i' must have explicitly specified data sharing attributes}} expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} foo(); +#ifndef OMP51 +#pragma omp target parallel for simd default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target parallel for simd default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < argc; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/target_teams_default_messages.cpp b/clang/test/OpenMP/target_teams_default_messages.cpp --- a/clang/test/OpenMP/target_teams_default_messages.cpp +++ b/clang/test/OpenMP/target_teams_default_messages.cpp @@ -1,21 +1,27 @@ // RUN: %clang_cc1 -verify -fopenmp -o - %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-simd -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -o - %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target teams default // expected-error {{expected '(' after 'default'}} foo(); -#pragma omp target teams default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target teams default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} foo(); -#pragma omp target teams default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target teams default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} foo(); #pragma omp target teams default (shared), default(shared) // expected-error {{directive '#pragma omp target teams' cannot contain more than one 'default' clause}} foo(); -#pragma omp target teams default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target teams default(none) // expected-note {{explicit data sharing attribute requested here}} @@ -24,5 +30,16 @@ #pragma omp target teams default(none) // expected-note {{explicit data sharing attribute requested here}} #pragma omp parallel default(shared) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + +#ifndef OMP51 +#pragma omp target teams default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target teams default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/target_teams_distribute_default_messages.cpp b/clang/test/OpenMP/target_teams_distribute_default_messages.cpp --- a/clang/test/OpenMP/target_teams_distribute_default_messages.cpp +++ b/clang/test/OpenMP/target_teams_distribute_default_messages.cpp @@ -1,25 +1,41 @@ // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -DOMP51 %s -Wuninitialized void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target teams distribute default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); - #pragma omp target teams distribute default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target teams distribute default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); - #pragma omp target teams distribute default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute default (shared), default(shared) // expected-error {{directive '#pragma omp target teams distribute' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); - #pragma omp target teams distribute default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#ifndef OMP51 +#pragma omp target teams distribute default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target teams distribute default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < 200; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp b/clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp --- a/clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp +++ b/clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp @@ -2,24 +2,41 @@ // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target teams distribute parallel for default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); - #pragma omp target teams distribute parallel for default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target teams distribute parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); -#pragma omp target teams distribute parallel for default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute parallel for default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute parallel for default (shared), default(shared) // expected-error {{directive '#pragma omp target teams distribute parallel for' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); -#pragma omp target teams distribute parallel for default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute parallel for default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#ifndef OMP51 +#pragma omp target teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < 200; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp b/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp --- a/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp +++ b/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp @@ -2,16 +2,23 @@ // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target teams distribute parallel for simd default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); -#pragma omp target teams distribute parallel for simd default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp target teams distribute parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); -#pragma omp target teams distribute parallel for simd default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute parallel for simd default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -20,11 +27,21 @@ #pragma omp target teams distribute parallel for simd default (shared), default(shared) // expected-error {{directive '#pragma omp target teams distribute parallel for simd' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); -#pragma omp target teams distribute parallel for simd default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp target teams distribute parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target teams distribute parallel for simd default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#ifndef OMP51 +#pragma omp target teams distribute parallel for simd default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp target teams distribute parallel for simd default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < argc; ++i) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/task_default_messages.cpp b/clang/test/OpenMP/task_default_messages.cpp --- a/clang/test/OpenMP/task_default_messages.cpp +++ b/clang/test/OpenMP/task_default_messages.cpp @@ -2,15 +2,22 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp task default // expected-error {{expected '(' after 'default'}} -#pragma omp task default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} -#pragma omp task default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp task default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp task default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} #pragma omp task default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} #pragma omp task default(shared), default(shared) // expected-error {{directive '#pragma omp task' cannot contain more than one 'default' clause}} -#pragma omp task default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp task default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} @@ -19,5 +26,15 @@ #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}} #pragma omp task default(shared) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + +#ifndef OMP51 +#pragma omp task default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp task default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } return 0; } diff --git a/clang/test/OpenMP/task_messages.cpp b/clang/test/OpenMP/task_messages.cpp --- a/clang/test/OpenMP/task_messages.cpp +++ b/clang/test/OpenMP/task_messages.cpp @@ -2,6 +2,8 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized + void xxx(int argc) { int x; // expected-note {{initialize the variable 'x' to silence this warning}} #pragma omp task @@ -11,6 +13,11 @@ void foo() { } +namespace { +static int y = 0; +} +static int x = 0; + #pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}} class S { @@ -47,6 +54,17 @@ #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}} #pragma omp task default(shared) ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}} +#ifndef OMP51 +#pragma omp task default(firstprivate) // expected-note 4 {{explicit data sharing attribute requested here}} expected-error 3 {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp task default(firstprivate) // expected-note 4 {{explicit data sharing attribute requested here}} +#endif +#pragma omp task +{ + ++x; // expected-error 2 {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error 2 {{variable 'y' must have explicitly specified data sharing attributes}} +} + #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}} #pragma omp task // expected-error@+1 {{calling a private constructor of class 'S'}} diff --git a/clang/test/OpenMP/teams_default_messages.cpp b/clang/test/OpenMP/teams_default_messages.cpp --- a/clang/test/OpenMP/teams_default_messages.cpp +++ b/clang/test/OpenMP/teams_default_messages.cpp @@ -2,17 +2,24 @@ // RUN: %clang_cc1 -verify -fopenmp-simd -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd -o - %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target #pragma omp teams default // expected-error {{expected '(' after 'default'}} foo(); #pragma omp target - #pragma omp teams default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp teams default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} foo(); #pragma omp target - #pragma omp teams default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target #pragma omp teams default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -21,7 +28,7 @@ #pragma omp teams default (shared), default(shared) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'default' clause}} foo(); #pragma omp target - #pragma omp teams default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} foo(); #pragma omp target @@ -32,5 +39,16 @@ #pragma omp teams default(none) // expected-note {{explicit data sharing attribute requested here}} #pragma omp parallel default(shared) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + +#pragma omp target +#ifndef OMP51 +#pragma omp teams default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp teams default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif +{ + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} +} return 0; } diff --git a/clang/test/OpenMP/teams_distribute_default_messages.cpp b/clang/test/OpenMP/teams_distribute_default_messages.cpp --- a/clang/test/OpenMP/teams_distribute_default_messages.cpp +++ b/clang/test/OpenMP/teams_distribute_default_messages.cpp @@ -2,17 +2,24 @@ // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target #pragma omp teams distribute default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp teams distribute default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -21,12 +28,23 @@ #pragma omp teams distribute default (shared), default(shared) // expected-error {{directive '#pragma omp teams distribute' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#pragma omp target +#ifndef OMP51 +#pragma omp teams distribute default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp teams distribute default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < 200; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp b/clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp --- a/clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp +++ b/clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp @@ -2,17 +2,24 @@ // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-version=51 -DOMP51 -fopenmp-simd %s -Wuninitialized + void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target #pragma omp teams distribute parallel for default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp teams distribute parallel for default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute parallel for default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute parallel for default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -21,12 +28,23 @@ #pragma omp teams distribute parallel for default (shared), default(shared) // expected-error {{directive '#pragma omp teams distribute parallel for' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute parallel for default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute parallel for default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#pragma omp target +#ifndef OMP51 +#pragma omp teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < 200; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp b/clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp --- a/clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp +++ b/clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp @@ -4,15 +4,20 @@ void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target #pragma omp teams distribute parallel for simd default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for simd default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp teams distribute parallel for simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for simd default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute parallel for simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute parallel for simd default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -21,12 +26,23 @@ #pragma omp teams distribute parallel for simd default (shared), default(shared) // expected-error {{directive '#pragma omp teams distribute parallel for simd' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute parallel for simd default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute parallel for simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute parallel for simd default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#pragma omp target +#ifndef OMP51 +#pragma omp teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} expected-error {{data-sharing attribute 'firstprivate' in 'default' clause requires OpenMP version 5.1 or above}} +#else +#pragma omp teams distribute parallel for default(firstprivate) // expected-note 2 {{explicit data sharing attribute requested here}} +#endif + for (int i = 0; i < 200; i++) { + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + } + return 0; } diff --git a/clang/test/OpenMP/teams_distribute_simd_default_messages.cpp b/clang/test/OpenMP/teams_distribute_simd_default_messages.cpp --- a/clang/test/OpenMP/teams_distribute_simd_default_messages.cpp +++ b/clang/test/OpenMP/teams_distribute_simd_default_messages.cpp @@ -1,18 +1,23 @@ -// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized -fopenmp-version=51 -// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized -fopenmp-version=51 void foo(); +namespace { +static int y = 0; +} +static int x = 0; + int main(int argc, char **argv) { #pragma omp target #pragma omp teams distribute simd default // expected-error {{expected '(' after 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute simd default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} +#pragma omp teams distribute simd default( // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute simd default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute simd default() // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute simd default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} @@ -21,12 +26,22 @@ #pragma omp teams distribute simd default (shared), default(shared) // expected-error {{directive '#pragma omp teams distribute simd' cannot contain more than one 'default' clause}} for (int i=0; i<200; i++) foo(); #pragma omp target - #pragma omp teams distribute simd default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} +#pragma omp teams distribute simd default(x) // expected-error {{expected 'none', 'shared' or 'firstprivate' in OpenMP clause 'default'}} for (int i=0; i<200; i++) foo(); #pragma omp target #pragma omp teams distribute simd default(none) // expected-note {{explicit data sharing attribute requested here}} for (int i=0; i<200; i++) ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} +#pragma omp target +#pragma omp teams distribute simd default(firstprivate) // expected-note {{explicit data sharing attribute requested here}} + for (int i = 0; i < 200; i++) + ++x; // expected-error {{variable 'x' must have explicitly specified data sharing attributes}} + +#pragma omp target +#pragma omp teams distribute simd default(firstprivate) // expected-note {{explicit data sharing attribute requested here}} + for (int i = 0; i < 200; i++) + ++y; // expected-error {{variable 'y' must have explicitly specified data sharing attributes}} + return 0; } diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2812,11 +2812,18 @@ EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher)); const std::string Source4 = R"( +void x() { +#pragma omp parallel default(firstprivate) +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher)); + + const std::string Source5 = R"( void x(int x) { #pragma omp parallel num_threads(x) ; })"; - EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher)); + EXPECT_TRUE(matchesWithOpenMP(Source5, Matcher)); } TEST(OMPDefaultClause, isNoneKind) { @@ -2852,10 +2859,17 @@ const std::string Source4 = R"( void x(int x) { -#pragma omp parallel num_threads(x) +#pragma omp parallel default(firstprivate) ; })"; EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher)); + + const std::string Source5 = R"( +void x(int x) { +#pragma omp parallel num_threads(x) +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher)); } TEST(OMPDefaultClause, isSharedKind) { @@ -2891,10 +2905,63 @@ const std::string Source4 = R"( void x(int x) { -#pragma omp parallel num_threads(x) +#pragma omp parallel default(firstprivate) ; })"; EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher)); + + const std::string Source5 = R"( +void x(int x) { +#pragma omp parallel num_threads(x) +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher)); +} + +TEST(OMPDefaultClause, isFirstPrivateKind) { + auto Matcher = ompExecutableDirective( + hasAnyClause(ompDefaultClause(isFirstPrivateKind()))); + + const std::string Source0 = R"( +void x() { +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher)); + + const std::string Source1 = R"( +void x() { +#pragma omp parallel +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher)); + + const std::string Source2 = R"( +void x() { +#pragma omp parallel default(shared) +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher)); + + const std::string Source3 = R"( +void x() { +#pragma omp parallel default(none) +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher)); + + const std::string Source4 = R"( +void x(int x) { +#pragma omp parallel default(firstprivate) +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher)); + + const std::string Source5 = R"( +void x(int x) { +#pragma omp parallel num_threads(x) +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher)); } TEST(OMPExecutableDirective, isAllowedToContainClauseKind) { @@ -2929,24 +2996,31 @@ EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher)); const std::string Source4 = R"( -void x(int x) { -#pragma omp parallel num_threads(x) +void x() { +#pragma omp parallel default(firstprivate) ; })"; EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher)); const std::string Source5 = R"( +void x(int x) { +#pragma omp parallel num_threads(x) +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source5, Matcher)); + + const std::string Source6 = R"( void x() { #pragma omp taskyield })"; - EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher)); + EXPECT_TRUE(notMatchesWithOpenMP(Source6, Matcher)); - const std::string Source6 = R"( + const std::string Source7 = R"( void x() { #pragma omp task ; })"; - EXPECT_TRUE(matchesWithOpenMP(Source6, Matcher)); + EXPECT_TRUE(matchesWithOpenMP(Source7, Matcher)); } } // namespace ast_matchers diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1843,11 +1843,18 @@ EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher)); const std::string Source4 = R"( +void x() { +#pragma omp parallel default(firstprivate) +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher)); + + const std::string Source5 = R"( void x(int x) { #pragma omp parallel num_threads(x) ; })"; - EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher)); + EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher)); } TEST(MatchFinderAPI, matchesDynamic) { diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def --- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def +++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def @@ -381,6 +381,7 @@ __OMP_DEFAULT_KIND(none) __OMP_DEFAULT_KIND(shared) +__OMP_DEFAULT_KIND(firstprivate) __OMP_DEFAULT_KIND(unknown) #undef __OMP_DEFAULT_KIND