66 changes: 65 additions & 1 deletion clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,14 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
Params);
break;
}
case OMPD_parallel_sections: {
Sema::CapturedParamNameType Params[] = {
std::make_pair(StringRef(), QualType()) // __context with shared vars
};
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
Params);
break;
}
case OMPD_threadprivate:
case OMPD_task:
llvm_unreachable("OpenMP Directive is not allowed");
Expand All @@ -998,6 +1006,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | parallel | section | + |
// | parallel | single | * |
// | parallel | parallel for | * |
// | parallel |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | for | parallel | * |
// | for | for | + |
Expand All @@ -1006,6 +1015,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | for | section | + |
// | for | single | + |
// | for | parallel for | * |
// | for |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | simd | parallel | |
// | simd | for | |
Expand All @@ -1014,6 +1024,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | simd | section | |
// | simd | single | |
// | simd | parallel for | |
// | simd |parallel sections| |
// +------------------+-----------------+------------------------------------+
// | sections | parallel | * |
// | sections | for | + |
Expand All @@ -1022,6 +1033,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | sections | section | * |
// | sections | single | + |
// | sections | parallel for | * |
// | sections |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | section | parallel | * |
// | section | for | + |
Expand All @@ -1030,6 +1042,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | section | section | + |
// | section | single | + |
// | section | parallel for | * |
// | section |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | single | parallel | * |
// | single | for | + |
Expand All @@ -1038,6 +1051,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | single | section | + |
// | single | single | + |
// | single | parallel for | * |
// | single |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | parallel for | parallel | * |
// | parallel for | for | + |
Expand All @@ -1046,6 +1060,16 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// | parallel for | section | + |
// | parallel for | single | + |
// | parallel for | parallel for | * |
// | parallel for |parallel sections| * |
// +------------------+-----------------+------------------------------------+
// | parallel sections| parallel | * |
// | parallel sections| for | + |
// | parallel sections| simd | * |
// | parallel sections| sections | + |
// | parallel sections| section | * |
// | parallel sections| single | + |
// | parallel sections| parallel for | * |
// | parallel sections|parallel sections| * |
// +------------------+-----------------+------------------------------------+
if (Stack->getCurScope()) {
auto ParentRegion = Stack->getParentDirective();
Expand All @@ -1063,7 +1087,8 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
// Orphaned section directives are prohibited. That is, the section
// directives must appear within the sections construct and must not be
// encountered elsewhere in the sections region.
if (ParentRegion != OMPD_sections) {
if (ParentRegion != OMPD_sections &&
ParentRegion != OMPD_parallel_sections) {
SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive)
<< (ParentRegion != OMPD_unknown)
<< getOpenMPDirectiveName(ParentRegion);
Expand Down Expand Up @@ -1155,6 +1180,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc,
EndLoc, VarsWithInheritedDSA);
break;
case OMPD_parallel_sections:
Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt,
StartLoc, EndLoc);
break;
case OMPD_threadprivate:
case OMPD_task:
llvm_unreachable("OpenMP Directive is not allowed");
Expand Down Expand Up @@ -1834,6 +1863,41 @@ StmtResult Sema::ActOnOpenMPParallelForDirective(
NestedLoopCount, Clauses, AStmt);
}

StmtResult
Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt, SourceLocation StartLoc,
SourceLocation EndLoc) {
assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
auto BaseStmt = AStmt;
while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
BaseStmt = CS->getCapturedStmt();
if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
auto S = C->children();
if (!S)
return StmtError();
// All associated statements must be '#pragma omp section' except for
// the first one.
for (++S; S; ++S) {
auto SectionStmt = *S;
if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
if (SectionStmt)
Diag(SectionStmt->getLocStart(),
diag::err_omp_parallel_sections_substmt_not_section);
return StmtError();
}
}
} else {
Diag(AStmt->getLocStart(),
diag::err_omp_parallel_sections_not_compound_stmt);
return StmtError();
}

getCurFunction()->setHasBranchProtectedScope();

return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc,
Clauses, AStmt);
}

OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
SourceLocation StartLoc,
SourceLocation LParenLoc,
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6494,6 +6494,17 @@ StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
return Res;
}

template <typename Derived>
StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
OMPParallelSectionsDirective *D) {
DeclarationNameInfo DirName;
getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
nullptr, D->getLocStart());
StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
getDerived().getSema().EndOpenMPDSABlock(Res.get());
return Res;
}

//===----------------------------------------------------------------------===//
// OpenMP clause transformation
//===----------------------------------------------------------------------===//
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Serialization/ASTReaderStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,14 @@ void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
VisitOMPExecutableDirective(D);
}

void ASTStmtReader::VisitOMPParallelSectionsDirective(
OMPParallelSectionsDirective *D) {
VisitStmt(D);
// The NumClauses field was read in ReadStmtFromStream.
++Idx;
VisitOMPExecutableDirective(D);
}

//===----------------------------------------------------------------------===//
// ASTReader Implementation
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -2470,6 +2478,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
break;
}

case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
S = OMPParallelSectionsDirective::CreateEmpty(
Context, Record[ASTStmtReader::NumStmtFields], Empty);
break;

case EXPR_CXX_OPERATOR_CALL:
S = new (Context) CXXOperatorCallExpr(Context, Empty);
break;
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Serialization/ASTWriterStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,14 @@ void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE;
}

void ASTStmtWriter::VisitOMPParallelSectionsDirective(
OMPParallelSectionsDirective *D) {
VisitStmt(D);
Record.push_back(D->getNumClauses());
VisitOMPExecutableDirective(D);
Code = serialization::STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE;
}

//===----------------------------------------------------------------------===//
// ASTWriter Implementation
//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
case Stmt::OMPSectionDirectiveClass:
case Stmt::OMPSingleDirectiveClass:
case Stmt::OMPParallelForDirectiveClass:
case Stmt::OMPParallelSectionsDirectiveClass:
llvm_unreachable("Stmt should not be in analyzer evaluation loop");

case Stmt::ObjCSubscriptRefExprClass:
Expand Down
224 changes: 224 additions & 0 deletions clang/test/OpenMP/nesting_of_regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ void foo() {
#pragma omp parallel for
for (int i = 0; i < 10; ++i)
;
#pragma omp parallel
#pragma omp parallel sections
{
bar();
}

// SIMD DIRECTIVE
#pragma omp simd
Expand Down Expand Up @@ -77,6 +82,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
bar();
}
}

// FOR DIRECTIVE
#pragma omp for
Expand Down Expand Up @@ -141,6 +153,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections
{
bar();
}
}

// SECTIONS DIRECTIVE
#pragma omp sections
Expand Down Expand Up @@ -206,6 +225,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp sections
{
#pragma omp parallel sections
{
bar();
}
}

// SECTION DIRECTIVE
#pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
Expand Down Expand Up @@ -269,6 +295,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp single
{
#pragma omp parallel sections
{
bar();
}
}

// PARALLEL FOR DIRECTIVE
#pragma omp parallel for
Expand Down Expand Up @@ -333,6 +366,85 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel for
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections
{
bar();
}
}

// PARALLEL SECTIONS DIRECTIVE
#pragma omp parallel sections
{
#pragma omp for // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp simd
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp parallel
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp sections // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
#pragma omp parallel sections
{
#pragma omp section
{
bar();
}
}
#pragma omp parallel sections
{
#pragma omp section
{
#pragma omp single // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
bar();
}
}
#pragma omp parallel sections
{
#pragma omp parallel
{
#pragma omp single // OK
{
bar();
}
#pragma omp for // OK
for (int i = 0; i < 10; ++i)
;
#pragma omp sections // OK
{
bar();
}
}
}
#pragma omp parallel sections
{
#pragma omp parallel for
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp parallel sections
{
bar();
}
}
}

void foo() {
Expand Down Expand Up @@ -367,6 +479,11 @@ void foo() {
#pragma omp parallel for
for (int i = 0; i < 10; ++i)
;
#pragma omp parallel
#pragma omp parallel sections
{
bar();
}

// SIMD DIRECTIVE
#pragma omp simd
Expand Down Expand Up @@ -412,6 +529,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
bar();
}
}

// FOR DIRECTIVE
#pragma omp for
Expand Down Expand Up @@ -474,6 +598,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections
{
bar();
}
}

// SECTIONS DIRECTIVE
#pragma omp sections
Expand Down Expand Up @@ -536,6 +667,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp sections
{
#pragma omp parallel sections
{
bar();
}
}

// SECTION DIRECTIVE
#pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}}
Expand Down Expand Up @@ -599,6 +737,13 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp single
{
#pragma omp parallel sections
{
bar();
}
}

// PARALLEL FOR DIRECTIVE
#pragma omp parallel for
Expand Down Expand Up @@ -663,6 +808,85 @@ void foo() {
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel for
for (int i = 0; i < 10; ++i) {
#pragma omp parallel sections
{
bar();
}
}

// PARALLEL SECTIONS DIRECTIVE
#pragma omp parallel sections
{
#pragma omp for // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp simd
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp parallel
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp sections // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
#pragma omp parallel sections
{
#pragma omp section
{
bar();
}
}
#pragma omp parallel sections
{
#pragma omp section
{
#pragma omp single // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}}
bar();
}
}
#pragma omp parallel sections
{
#pragma omp parallel
{
#pragma omp single // OK
{
bar();
}
#pragma omp for // OK
for (int i = 0; i < 10; ++i)
;
#pragma omp sections // OK
{
bar();
}
}
}
#pragma omp parallel sections
{
#pragma omp parallel for
for (int i = 0; i < 10; ++i)
;
}
#pragma omp parallel sections
{
#pragma omp parallel sections
{
bar();
}
}
return foo<int>();
}

144 changes: 144 additions & 0 deletions clang/test/OpenMP/parallel_sections_ast_print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s
// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s
// RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
// expected-no-diagnostics

#ifndef HEADER
#define HEADER

void foo() {}

template <class T>
struct S {
operator T() { return T(); }
static T TS;
#pragma omp threadprivate(TS)
};

// CHECK: template <class T = int> struct S {
// CHECK: static int TS;
// CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
// CHECK-NEXT: }
// CHECK: template <class T = long> struct S {
// CHECK: static long TS;
// CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
// CHECK-NEXT: }
// CHECK: template <class T> struct S {
// CHECK: static T TS;
// CHECK-NEXT: #pragma omp threadprivate(S::TS)
// CHECK: };

template <typename T, int C>
T tmain(T argc, T *argv) {
T b = argc, c, d, e, f, g;
static T a;
S<T> s;
#pragma omp parallel sections
{
a = 2;
}
#pragma omp parallel sections default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) num_threads(C) copyin(S < T > ::TS) proc_bind(master) reduction(+ : c) reduction(max : e)
{
foo();
}
#pragma omp parallel sections if (C) num_threads(s) proc_bind(close) reduction(^ : e, f) reduction(&& : g) lastprivate(b, c)
{
foo();
#pragma omp section
foo();
}
return 0;
}

// CHECK: template <typename T = int, int C = 5> int tmain(int argc, int *argv) {
// CHECK-NEXT: int b = argc, c, d, e, f, g;
// CHECK-NEXT: static int a;
// CHECK-NEXT: S<int> s;
// CHECK-NEXT: #pragma omp parallel sections
// CHECK-NEXT: {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(5) copyin(S<int>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections if(5) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: #pragma omp section
// CHECK-NEXT: foo();
// CHECK-NEXT: }
// CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) {
// CHECK-NEXT: long b = argc, c, d, e, f, g;
// CHECK-NEXT: static long a;
// CHECK-NEXT: S<long> s;
// CHECK-NEXT: #pragma omp parallel sections
// CHECK-NEXT: {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(1) copyin(S<long>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections if(1) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: #pragma omp section
// CHECK-NEXT: foo();
// CHECK-NEXT: }
// CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
// CHECK-NEXT: T b = argc, c, d, e, f, g;
// CHECK-NEXT: static T a;
// CHECK-NEXT: S<T> s;
// CHECK-NEXT: #pragma omp parallel sections
// CHECK-NEXT: {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) num_threads(C) copyin(S<T>::TS) proc_bind(master) reduction(+: c) reduction(max: e)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp parallel sections if(C) num_threads(s) proc_bind(close) reduction(^: e,f) reduction(&&: g) lastprivate(b,c)
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: #pragma omp section
// CHECK-NEXT: foo();
// CHECK-NEXT: }

enum Enum {};

int main(int argc, char **argv) {
long x;
int b = argc, c, d, e, f, g;
static int a;
#pragma omp threadprivate(a)
Enum ee;
// CHECK: Enum ee;
#pragma omp parallel sections
// CHECK-NEXT: #pragma omp parallel sections
{
a = 2;
}
// CHECK-NEXT: {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: }
#pragma omp parallel sections default(none), private(argc, b) firstprivate(argv) if (argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d) reduction(* : e) lastprivate(argv)
// CHECK-NEXT: #pragma omp parallel sections default(none) private(argc,b) firstprivate(argv) if(argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d) reduction(*: e) lastprivate(argv)
{
foo();
#pragma omp section
foo();
#pragma omp section
foo();
}
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: #pragma omp section
// CHECK-NEXT: foo();
// CHECK-NEXT: #pragma omp section
// CHECK-NEXT: foo();
// CHECK-NEXT: }
return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
}

#endif
105 changes: 105 additions & 0 deletions clang/test/OpenMP/parallel_sections_copyin_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note {{declared here}}
class S2 {
mutable int a;

public:
S2() : a(0) {}
S2 &operator=(S2 &s2) { return *this; }
};
class S3 {
int a;

public:
S3() : a(0) {}
S3 &operator=(S3 &s3) { return *this; }
};
class S4 { // expected-note {{'S4' declared here}}
int a;
S4();
S4 &operator=(const S4 &s4);

public:
S4(int v) : a(v) {}
};
class S5 { // expected-note {{'S5' declared here}}
int a;
S5() : a(0) {}
S5 &operator=(const S5 &s5) { return *this; }

public:
S5(int v) : a(v) {}
};
template <class T>
class ST {
public:
static T s;
};

S2 k;
S3 h;
S4 l(3); // expected-note {{'l' defined here}}
S5 m(4); // expected-note {{'m' defined here}}
#pragma omp threadprivate(h, k, l, m)

int main(int argc, char **argv) {
int i;
#pragma omp parallel sections copyin // expected-error {{expected '(' after 'copyin'}}
{
foo();
}
#pragma omp parallel sections copyin( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections copyin() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections copyin(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections copyin(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections copyin(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections copyin(l) // expected-error {{copyin variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel sections copyin(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections copyin(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections copyin(i) // expected-error {{copyin variable must be threadprivate}}
{
foo();
}
#pragma omp parallel sections copyin(m) // expected-error {{copyin variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel sections copyin(ST < int > ::s) // expected-error {{copyin variable must be threadprivate}}
{
foo();
}

return 0;
}
39 changes: 39 additions & 0 deletions clang/test/OpenMP/parallel_sections_default_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s

void foo();

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' or 'shared' 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'}}
{
foo();
}
}
}
}
}
}

#pragma omp parallel sections default(none)
{
++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
}

#pragma omp parallel sections default(none)
{
#pragma omp parallel sections default(shared)
{
++argc;
}
}
return 0;
}
295 changes: 295 additions & 0 deletions clang/test/OpenMP/parallel_sections_firstprivate_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

public:
S2() : a(0) {}
S2(S2 &s2) : a(s2.a) {}
static float S2s;
static const float S2sc;
};
const float S2::S2sc = 0;
const S2 b;
const S2 ba[5];
class S3 {
int a;
S3 &operator=(const S3 &s3);

public:
S3() : a(0) {}
S3(S3 &s3) : a(s3.a) {}
};
const S3 c;
const S3 ca[5];
extern const int f;
class S4 { // expected-note 2 {{'S4' declared here}}
int a;
S4();
S4(const S4 &s4);

public:
S4(int v) : a(v) {}
};
class S5 { // expected-note 4 {{'S5' declared here}}
int a;
S5(const S5 &s5) : a(s5.a) {}

public:
S5() : a(0) {}
S5(int v) : a(v) {}
};
class S6 {
int a;
S6() : a(0) {}

public:
S6(const S6 &s6) : a(s6.a) {}
S6(int v) : a(v) {}
};

S3 h;
#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}

template <class I, class C>
int foomain(int argc, char **argv) {
I e(4); // expected-note {{'e' defined here}}
C g(5); // expected-note 2 {{'g' defined here}}
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
{
foo();
}
#pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc)
{
foo();
}
#pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
{
foo();
}
#pragma omp parallel sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i;
#pragma omp parallel sections firstprivate(i)
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp parallel sections firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections firstprivate(i)
{
foo();
}
#pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel private(i)
#pragma omp parallel sections firstprivate(i)
{
foo();
}
#pragma omp parallel reduction(+ : i)
#pragma omp parallel sections firstprivate(i)
{
foo();
}
return 0;
}

int main(int argc, char **argv) {
const int d = 5;
const int da[5] = {0};
S4 e(4); // expected-note {{'e' defined here}}
S5 g(5); // expected-note 2 {{'g' defined here}}
S3 m;
S6 n(2);
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
{
foo();
}
#pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections firstprivate(argc)
{
foo();
}
#pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections firstprivate(2 * 2) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections firstprivate(ba) // OK
{
foo();
}
#pragma omp parallel sections firstprivate(ca) // OK
{
foo();
}
#pragma omp parallel sections firstprivate(da) // OK
{
foo();
}
int xa;
#pragma omp parallel sections firstprivate(xa) // OK
{
foo();
}
#pragma omp parallel sections firstprivate(S2::S2s) // OK
{
foo();
}
#pragma omp parallel sections firstprivate(S2::S2sc) // OK
{
foo();
}
#pragma omp parallel sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel sections firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel sections firstprivate(m) // OK
{
foo();
}
#pragma omp parallel sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
{
foo();
}
#pragma omp parallel sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
{
foo();
}
#pragma omp parallel shared(xa)
#pragma omp parallel sections firstprivate(xa) // OK: may be firstprivate
{
foo();
}
#pragma omp parallel sections firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel sections lastprivate(n) firstprivate(n) // OK
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i;
#pragma omp parallel sections firstprivate(i)
{
foo();
}
v += i;
}
#pragma omp parallel private(i)
#pragma omp parallel sections firstprivate(i)
{
foo();
}
#pragma omp parallel reduction(+ : i)
#pragma omp parallel sections firstprivate(i)
{
foo();
}

return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
}
113 changes: 113 additions & 0 deletions clang/test/OpenMP/parallel_sections_if_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note {{declared here}}

template <class T, class S> // expected-note {{declared here}}
int tmain(T argc, S **argv) {
#pragma omp parallel sections if // expected-error {{expected '(' after 'if'}}
{
foo();
}
#pragma omp parallel sections if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if () // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections if (argc > 0 ? argv[1] : argv[2])
{
foo();
}
#pragma omp parallel sections if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause}}
{
foo();
}
#pragma omp parallel sections if (S) // expected-error {{'S' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if(argc)
{
foo();
}

return 0;
}

int main(int argc, char **argv) {
#pragma omp parallel sections if // expected-error {{expected '(' after 'if'}}
{
foo();
}
#pragma omp parallel sections if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if () // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections if (argc > 0 ? argv[1] : argv[2])
{
foo();
}
#pragma omp parallel sections if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause}}
{
foo();
}
#pragma omp parallel sections if (S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}

return tmain(argc, argv);
}
269 changes: 269 additions & 0 deletions clang/test/OpenMP/parallel_sections_lastprivate_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

public:
S2() : a(0) {}
S2(S2 &s2) : a(s2.a) {}
static float S2s; // expected-note {{static data member is predetermined as shared}}
static const float S2sc;
};
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
const S2 b;
const S2 ba[5];
class S3 { // expected-note 2 {{'S3' declared here}}
int a;
S3 &operator=(const S3 &s3);

public:
S3() : a(0) {}
S3(S3 &s3) : a(s3.a) {}
};
const S3 c; // expected-note {{global variable is predetermined as shared}}
const S3 ca[5]; // expected-note {{global variable is predetermined as shared}}
extern const int f; // expected-note {{global variable is predetermined as shared}}
class S4 { // expected-note 3 {{'S4' declared here}}
int a;
S4();
S4(const S4 &s4);

public:
S4(int v) : a(v) {}
};
class S5 { // expected-note {{'S5' declared here}}
int a;
S5() : a(0) {}

public:
S5(const S5 &s5) : a(s5.a) {}
S5(int v) : a(v) {}
};
class S6 {
int a;
S6() : a(0) {}

public:
S6(const S6 &s6) : a(s6.a) {}
S6(int v) : a(v) {}
};

S3 h;
#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}

template <class I, class C>
int foomain(int argc, char **argv) {
I e(4); // expected-note {{'e' defined here}}
I g(5); // expected-note {{'g' defined here}}
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
{
foo();
}
#pragma omp parallel sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc)
{
foo();
}
#pragma omp parallel sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel sections lastprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp parallel sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i;
#pragma omp parallel sections lastprivate(i)
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp parallel sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections lastprivate(i)
{
foo();
}
return 0;
}

int main(int argc, char **argv) {
const int d = 5; // expected-note {{constant variable is predetermined as shared}}
const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
S4 e(4); // expected-note {{'e' defined here}}
S5 g(5); // expected-note {{'g' defined here}}
S3 m; // expected-note 2 {{'m' defined here}}
S6 n(2);
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
{
foo();
}
#pragma omp parallel sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections lastprivate(argc)
{
foo();
}
#pragma omp parallel sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections lastprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections lastprivate(2 * 2) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections lastprivate(ba)
{
foo();
}
#pragma omp parallel sections lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
int xa;
#pragma omp parallel sections lastprivate(xa) // OK
{
foo();
}
#pragma omp parallel sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel sections lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp parallel sections lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
{
foo();
}
#pragma omp parallel sections lastprivate(i)
{
foo();
}
#pragma omp parallel private(xa)
#pragma omp parallel sections lastprivate(xa)
{
foo();
}
#pragma omp parallel reduction(+ : xa)
#pragma omp parallel sections lastprivate(xa)
{
foo();
}
#pragma omp parallel sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections firstprivate(m) lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel sections lastprivate(n) firstprivate(n) // OK
{
foo();
}
return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
}
86 changes: 86 additions & 0 deletions clang/test/OpenMP/parallel_sections_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -std=c++11 -o - %s

void foo() {
}

#pragma omp parallel sections // expected-error {{unexpected OpenMP directive '#pragma omp parallel sections'}}

int main(int argc, char **argv) {
#pragma omp parallel sections {// expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections( // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections[ // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections] // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections } // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections unknown()
{
foo();
#pragma omp section
L1:
foo();
}
#pragma omp parallel sections
{
;
}
#pragma omp parallel sections
{
goto L1; // expected-error {{use of undeclared label 'L1'}}
}

for (int i = 0; i < 10; ++i) {
switch (argc) {
case (0):
#pragma omp parallel sections
{
foo();
break; // expected-error {{'break' statement not in loop or switch statement}}
continue; // expected-error {{'continue' statement not in loop statement}}
}
default:
break;
}
}
#pragma omp parallel sections default(none)
{
++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
}

goto L2; // expected-error {{use of undeclared label 'L2'}}
#pragma omp parallel sections
{
L2:
foo();
}
#pragma omp parallel sections
{
return 1; // expected-error {{cannot return from OpenMP region}}
}

[[]] // expected-error {{an attribute list cannot appear here}}
#pragma omp parallel sections
{
}

return 0;
}

260 changes: 260 additions & 0 deletions clang/test/OpenMP/parallel_sections_misc_messages.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s

void foo();

// expected-error@+1 {{unexpected OpenMP directive '#pragma omp parallel sections'}}
#pragma omp parallel sections

// expected-error@+1 {{unexpected OpenMP directive '#pragma omp parallel sections'}}
#pragma omp parallel sections foo

void test_no_clause() {
int i;
#pragma omp parallel sections
{
foo();
}

// expected-error@+2 {{the statement for '#pragma omp parallel sections' must be a compound statement}}
#pragma omp parallel sections
++i;

#pragma omp parallel sections
{
foo();
foo(); // expected-error {{statement in 'omp parallel sections' directive must be enclosed into a section region}}
}

}

void test_branch_protected_scope() {
int i = 0;
L1:
++i;

int x[24];

#pragma omp parallel sections
{
if (i == 5)
goto L1; // expected-error {{use of undeclared label 'L1'}}
else if (i == 6)
return; // expected-error {{cannot return from OpenMP region}}
else if (i == 7)
goto L2;
else if (i == 8) {
L2:
x[i]++;
}
#pragma omp section
if (i == 5)
goto L1; // expected-error {{use of undeclared label 'L1'}}
else if (i == 6)
return; // expected-error {{cannot return from OpenMP region}}
else if (i == 7)
goto L3;
else if (i == 8) {
L3:
x[i]++;
}
}

if (x[0] == 0)
goto L2; // expected-error {{use of undeclared label 'L2'}}
else if (x[1] == 1)
goto L1;
goto L3; // expected-error {{use of undeclared label 'L3'}}
}

void test_invalid_clause() {
int i;
// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections foo bar
{
foo();
// expected-error@+1 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp section'}}
#pragma omp section nowait
;
}
}

void test_non_identifiers() {
int i, x;

// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections;
{
foo();
}
// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}}
// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections linear(x);
{
foo();
}

// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections private(x);
{
foo();
}

// expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
#pragma omp parallel sections, private(x);
{
foo();
}
}

void test_private() {
int i;
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
#pragma omp parallel sections private(
{
foo();
}
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections private(,
{
foo();
}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections private(, )
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections private()
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections private(int)
{
foo();
}
// expected-error@+1 {{expected variable name}}
#pragma omp parallel sections private(0)
{
foo();
}

int x, y, z;
#pragma omp parallel sections private(x)
{
foo();
}
#pragma omp parallel sections private(x, y)
{
foo();
}
#pragma omp parallel sections private(x, y, z)
{
foo();
}
}

void test_lastprivate() {
int i;
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections lastprivate(
{
foo();
}

// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections lastprivate(,
{
foo();
}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections lastprivate(, )
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections lastprivate()
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections lastprivate(int)
{
foo();
}
// expected-error@+1 {{expected variable name}}
#pragma omp parallel sections lastprivate(0)
{
foo();
}

int x, y, z;
#pragma omp parallel sections lastprivate(x)
{
foo();
}
#pragma omp parallel sections lastprivate(x, y)
{
foo();
}
#pragma omp parallel sections lastprivate(x, y, z)
{
foo();
}
}

void test_firstprivate() {
int i;
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections firstprivate(
{
foo();
}

// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections firstprivate(,
{
foo();
}
// expected-error@+1 2 {{expected expression}}
#pragma omp parallel sections firstprivate(, )
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections firstprivate()
{
foo();
}
// expected-error@+1 {{expected expression}}
#pragma omp parallel sections firstprivate(int)
{
foo();
}
// expected-error@+1 {{expected variable name}}
#pragma omp parallel sections firstprivate(0)
{
foo();
}

int x, y, z;
#pragma omp parallel sections lastprivate(x) firstprivate(x)
{
foo();
}
#pragma omp parallel sections lastprivate(x, y) firstprivate(x, y)
{
foo();
}
#pragma omp parallel sections lastprivate(x, y, z) firstprivate(x, y, z)
{
foo();
}
}

63 changes: 63 additions & 0 deletions clang/test/OpenMP/parallel_sections_num_threads_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note {{declared here}}

template <class T, typename S, int N> // expected-note {{declared here}}
T tmain(T argc, S **argv) {
#pragma omp parallel sections num_threads // expected-error {{expected '(' after 'num_threads'}}
{foo();}
#pragma omp parallel sections num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{foo();}
#pragma omp parallel sections num_threads () // expected-error {{expected expression}}
{foo();}
#pragma omp parallel sections num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{foo();}
#pragma omp parallel sections num_threads (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{foo();}
#pragma omp parallel sections num_threads ((argc > 0) ? argv[1] : argv[2]) // expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}}
{foo();}
#pragma omp parallel sections num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel sections' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a positive integer value}}
{foo();}
#pragma omp parallel sections num_threads (S) // expected-error {{'S' does not refer to a value}}
{foo();}
#pragma omp parallel sections num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}}
{foo();}
#pragma omp parallel sections num_threads (argc)
{foo();}
#pragma omp parallel sections num_threads (N) // expected-error {{argument to 'num_threads' clause must be a positive integer value}}
{foo();}

return argc;
}

int main(int argc, char **argv) {
#pragma omp parallel sections num_threads // expected-error {{expected '(' after 'num_threads'}}
{foo();}
#pragma omp parallel sections num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{foo();}
#pragma omp parallel sections num_threads () // expected-error {{expected expression}}
{foo();}
#pragma omp parallel sections num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{foo();}
#pragma omp parallel sections num_threads (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{foo();}
#pragma omp parallel sections num_threads (argc > 0 ? argv[1] : argv[2]) // expected-error {{integral }}
{foo();}
#pragma omp parallel sections num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel sections' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a positive integer value}}
{foo();}
#pragma omp parallel sections num_threads (S1) // expected-error {{'S1' does not refer to a value}}
{foo();}
#pragma omp parallel sections num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}}
{foo();}
#pragma omp parallel sections num_threads (num_threads(tmain<int, char, -1>(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}} expected-note {{in instantiation of function template specialization 'tmain<int, char, -1>' requested here}}
{foo();}

return tmain<int, char, 3>(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char, 3>' requested here}}
}
204 changes: 204 additions & 0 deletions clang/test/OpenMP/parallel_sections_private_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

public:
S2() : a(0) {}
};
const S2 b;
const S2 ba[5];
class S3 {
int a;

public:
S3() : a(0) {}
};
const S3 ca[5];
class S4 { // expected-note {{'S4' declared here}}
int a;
S4();

public:
S4(int v) : a(v) {}
};
class S5 { // expected-note {{'S5' declared here}}
int a;
S5() : a(0) {}

public:
S5(int v) : a(v) {}
};

S3 h;
#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}

template <class I, class C>
int foomain(I argc, C **argv) {
I e(4);
I g(5);
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections private // expected-error {{expected '(' after 'private'}}
{
foo();
}
#pragma omp parallel sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections private(argc)
{
foo();
}
#pragma omp parallel sections private(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel sections private(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections private(e, g)
{
foo();
}
#pragma omp parallel sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
{
foo();
}
#pragma omp parallel sections copyprivate(i) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i;
#pragma omp parallel sections private(i)
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp parallel sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections private(i)
{
foo();
}
return 0;
}

int main(int argc, char **argv) {
S4 e(4); // expected-note {{'e' defined here}}
S5 g(5); // expected-note {{'g' defined here}}
int i;
int &j = i; // expected-note {{'j' defined here}}
#pragma omp parallel sections private // expected-error {{expected '(' after 'private'}}
{
foo();
}
#pragma omp parallel sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections private(argc)
{
foo();
}
#pragma omp parallel sections private(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel sections private(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp parallel sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
{
foo();
}
#pragma omp parallel sections copyprivate(i) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel sections'}}
{
foo();
}
#pragma omp parallel
{
int i;
#pragma omp parallel sections private(i)
{
foo();
}
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp parallel sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
{
foo();
}
#pragma omp parallel sections private(i)
{
foo();
}

return 0;
}

28 changes: 28 additions & 0 deletions clang/test/OpenMP/parallel_sections_proc_bind_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s

void foo();

int main(int argc, char **argv) {
#pragma omp parallel sections proc_bind // expected-error {{expected '(' after 'proc_bind'}}
{ foo(); }
#pragma omp parallel sections proc_bind( // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{ foo(); }
#pragma omp parallel sections proc_bind() // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
{ foo(); }
#pragma omp parallel sections proc_bind(master // expected-error {{expected ')'}} expected-note {{to match this '('}}
{ foo(); }
#pragma omp parallel sections proc_bind(close), proc_bind(spread) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'proc_bind' clause}}
{ foo(); }
#pragma omp parallel sections proc_bind(x) // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}}
{ foo(); }

#pragma omp parallel sections proc_bind(master)
{ ++argc; }

#pragma omp parallel sections proc_bind(close)
{
#pragma omp parallel sections proc_bind(spread)
{ ++argc; }
}
return 0;
}
358 changes: 358 additions & 0 deletions clang/test/OpenMP/parallel_sections_reduction_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,358 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -o - %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;
S2 &operator+=(const S2 &arg) { return (*this); }

public:
S2() : a(0) {}
S2(S2 &s2) : a(s2.a) {}
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
static const float S2sc;
};
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
S2 b; // expected-note 2 {{'b' defined here}}
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
class S3 {
int a;

public:
S3() : a(0) {}
S3(const S3 &s3) : a(s3.a) {}
S3 operator+=(const S3 &arg1) { return arg1; }
};
int operator+=(const S3 &arg1, const S3 &arg2) { return 5; }
S3 c; // expected-note 2 {{'c' defined here}}
const S3 ca[5]; // expected-note 2 {{'ca' defined here}}
extern const int f; // expected-note 4 {{'f' declared here}}
class S4 { // expected-note {{'S4' declared here}}
int a;
S4();
S4(const S4 &s4);
S4 &operator+=(const S4 &arg) { return (*this); }

public:
S4(int v) : a(v) {}
};
S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
class S5 {
int a;
S5() : a(0) {}
S5(const S5 &s5) : a(s5.a) {}
S5 &operator+=(const S5 &arg);

public:
S5(int v) : a(v) {}
};
class S6 {
int a;

public:
S6() : a(6) {}
operator int() { return 6; }
} o; // expected-note 2 {{'o' defined here}}

S3 h, k;
#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}

template <class T> // expected-note {{declared here}}
T tmain(T argc) { // expected-note 2 {{'argc' defined here}}
const T d = T(); // expected-note 4 {{'d' defined here}}
const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
T qa[5] = {T()};
T i;
T &j = i; // expected-note 4 {{'j' defined here}}
S3 &p = k; // expected-note 2 {{'p' defined here}}
const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}}
T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}}
T fl; // expected-note {{'fl' defined here}}
#pragma omp parallel sections reduction // expected-error {{expected '(' after 'reduction'}}
{
foo();
}
#pragma omp parallel sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel sections reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name}}
{
foo();
}
#pragma omp parallel sections reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
{
foo();
}
#pragma omp parallel sections reduction(&& : argc)
{
foo();
}
#pragma omp parallel sections reduction(^ : T) // expected-error {{'T' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections reduction(+ : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(min : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(max : qa[1]) // expected-error 2 {{expected variable name}}
{
foo();
}
#pragma omp parallel sections reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(- : da) // expected-error {{a reduction variable with array type 'const int [5]'}} expected-error {{a reduction variable with array type 'const float [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel private(k)
#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 3 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 3 {{previously referenced here}}
{
foo();
}
#pragma omp parallel sections reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel shared(i)
#pragma omp parallel reduction(min : i)
#pragma omp parallel sections reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel private(fl)
#pragma omp parallel sections reduction(+ : fl)
{
foo();
}
#pragma omp parallel reduction(* : fl)
#pragma omp parallel sections reduction(+ : fl)
{
foo();
}

return T();
}

int main(int argc, char **argv) {
const int d = 5; // expected-note 2 {{'d' defined here}}
const int da[5] = {0}; // expected-note {{'da' defined here}}
int qa[5] = {0};
S4 e(4); // expected-note {{'e' defined here}}
S5 g(5); // expected-note {{'g' defined here}}
int i;
int &j = i; // expected-note 2 {{'j' defined here}}
S3 &p = k; // expected-note 2 {{'p' defined here}}
const int &r = da[i]; // expected-note {{'r' defined here}}
int &q = qa[i]; // expected-note {{'q' defined here}}
float fl; // expected-note {{'fl' defined here}}
#pragma omp parallel sections reduction // expected-error {{expected '(' after 'reduction'}}
{
foo();
}
#pragma omp parallel sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
{
foo();
}
#pragma omp parallel sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel sections reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
{
foo();
}
#pragma omp parallel sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel sections reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections reduction(~ : argc) // expected-error {{expected unqualified-id}}
{
foo();
}
#pragma omp parallel sections reduction(&& : argc)
{
foo();
}
#pragma omp parallel sections reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel sections reduction(+ : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(min : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(max : argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel sections reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(- : da) // expected-error {{a reduction variable with array type 'const int [5]'}}
{
foo();
}
#pragma omp parallel sections reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(& : e, g) // expected-error {{reduction variable must have an accessible, unambiguous default constructor}} expected-error {{variable of type 'S5' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
{
foo();
}
#pragma omp parallel sections reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel private(k)
#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
{
foo();
}
#pragma omp parallel sections reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel shared(i)
#pragma omp parallel reduction(min : i)
#pragma omp parallel sections reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
{
foo();
}
#pragma omp parallel private(fl)
#pragma omp parallel sections reduction(+ : fl)
{
foo();
}
#pragma omp parallel reduction(* : fl)
#pragma omp parallel sections reduction(+ : fl)
{
foo();
}

return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}}
}
110 changes: 110 additions & 0 deletions clang/test/OpenMP/parallel_sections_shared_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s

void foo() {
}

bool foobool(int argc) {
return argc;
}

struct S1; // expected-note {{declared here}}
extern S1 a;
class S2 {
mutable int a;

public:
S2() : a(0) {}
S2(S2 &s2) : a(s2.a) {}
};
const S2 b;
const S2 ba[5];
class S3 {
int a;

public:
S3() : a(0) {}
S3(S3 &s3) : a(s3.a) {}
};
const S3 c;
const S3 ca[5];
extern const int f;
class S4 {
int a;
S4();
S4(const S4 &s4);

public:
S4(int v) : a(v) {}
};
class S5 {
int a;
S5() : a(0) {}
S5(const S5 &s5) : a(s5.a) {}

public:
S5(int v) : a(v) {}
};

S3 h;
#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}

int main(int argc, char **argv) {
const int d = 5;
const int da[5] = {0};
S4 e(4);
S5 g(5);
int i;
int &j = i;
#pragma omp parallel sections shared // expected-error {{expected '(' after 'shared'}}
{ foo(); }
#pragma omp parallel sections shared( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{ foo(); }
#pragma omp parallel sections shared() // expected-error {{expected expression}}
{ foo(); }
#pragma omp parallel sections shared(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{ foo(); }
#pragma omp parallel sections shared(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{ foo(); }
#pragma omp parallel sections shared(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{ foo(); }
#pragma omp parallel sections shared(argc)
{ foo(); }
#pragma omp parallel sections shared(S1) // expected-error {{'S1' does not refer to a value}}
{ foo(); }
#pragma omp parallel sections shared(a, b, c, d, f)
{ foo(); }
#pragma omp parallel sections shared(argv[1]) // expected-error {{expected variable name}}
{ foo(); }
#pragma omp parallel sections shared(ba)
{ foo(); }
#pragma omp parallel sections shared(ca)
{ foo(); }
#pragma omp parallel sections shared(da)
{ foo(); }
#pragma omp parallel sections shared(e, g)
{ foo(); }
#pragma omp parallel sections shared(h) // expected-error {{threadprivate or thread local variable cannot be shared}}
{ foo(); }
#pragma omp parallel sections private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}
{ foo(); }
#pragma omp parallel sections firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}}
{ foo(); }
#pragma omp parallel sections private(i)
{
#pragma omp parallel sections shared(i)
{
#pragma omp parallel sections shared(j)
{ foo(); }
}
}
#pragma omp parallel sections firstprivate(i)
{
#pragma omp parallel sections shared(i)
{
#pragma omp parallel sections shared(j)
{ foo(); }
}
}

return 0;
}
8 changes: 8 additions & 0 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,7 @@ class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
void VisitOMPSectionDirective(const OMPSectionDirective *D);
void VisitOMPSingleDirective(const OMPSingleDirective *D);
void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);

private:
void AddDeclarationNameInfo(const Stmt *S);
Expand Down Expand Up @@ -2317,6 +2318,11 @@ EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) {
VisitOMPExecutableDirective(D);
}

void EnqueueVisitor::VisitOMPParallelSectionsDirective(
const OMPParallelSectionsDirective *D) {
VisitOMPExecutableDirective(D);
}

void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
}
Expand Down Expand Up @@ -4003,6 +4009,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPSingleDirective");
case CXCursor_OMPParallelForDirective:
return cxstring::createRef("OMPParallelForDirective");
case CXCursor_OMPParallelSectionsDirective:
return cxstring::createRef("OMPParallelSectionsDirective");
}

llvm_unreachable("Unhandled CXCursorKind");
Expand Down
3 changes: 3 additions & 0 deletions clang/tools/libclang/CXCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
case Stmt::OMPParallelForDirectiveClass:
K = CXCursor_OMPParallelForDirective;
break;
case Stmt::OMPParallelSectionsDirectiveClass:
K = CXCursor_OMPParallelSectionsDirective;
break;
}

CXCursor C = { K, 0, { Parent, S, TU } };
Expand Down