12 changes: 12 additions & 0 deletions clang/lib/Serialization/ASTReaderStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,13 @@ void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
VisitOMPExecutableDirective(D);
}

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

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

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

case EXPR_CXX_OPERATOR_CALL:
S = new (Context) CXXOperatorCallExpr(Context, Empty);
break;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Serialization/ASTWriterStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,13 @@ void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) {
Code = serialization::STMT_OMP_FOR_DIRECTIVE;
}

void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
VisitStmt(D);
Record.push_back(D->getNumClauses());
VisitOMPExecutableDirective(D);
Code = serialization::STMT_OMP_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 @@ -733,6 +733,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
case Stmt::OMPParallelDirectiveClass:
case Stmt::OMPSimdDirectiveClass:
case Stmt::OMPForDirectiveClass:
case Stmt::OMPSectionsDirectiveClass:
llvm_unreachable("Stmt should not be in analyzer evaluation loop");

case Stmt::ObjCSubscriptRefExprClass:
Expand Down
84 changes: 84 additions & 0 deletions clang/test/OpenMP/nesting_of_regions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s

void bar();

template <class T>
void foo() {
#pragma omp parallel
Expand All @@ -8,6 +10,11 @@ void foo() {
#pragma omp parallel
#pragma omp simd
for (int i = 0; i < 10; ++i);
#pragma omp parallel
#pragma omp sections
{
bar();
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
Expand All @@ -23,6 +30,13 @@ void foo() {
#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
for (int i = 0; i < 10; ++i);
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
bar();
}
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
Expand All @@ -38,6 +52,35 @@ void foo() {
#pragma omp parallel
for (int i = 0; i < 10; ++i);
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp sections // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
#pragma omp sections
{
#pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp simd
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp parallel
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp sections // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
}

void foo() {
Expand All @@ -47,6 +90,11 @@ void foo() {
#pragma omp parallel
#pragma omp simd
for (int i = 0; i < 10; ++i);
#pragma omp parallel
#pragma omp sections
{
bar();
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}}
Expand All @@ -62,6 +110,13 @@ void foo() {
#pragma omp parallel // expected-error {{OpenMP constructs may not be nested inside a simd region}}
for (int i = 0; i < 10; ++i);
}
#pragma omp simd
for (int i = 0; i < 10; ++i) {
#pragma omp sections // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
bar();
}
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
Expand All @@ -77,6 +132,35 @@ void foo() {
#pragma omp parallel
for (int i = 0; i < 10; ++i);
}
#pragma omp for
for (int i = 0; i < 10; ++i) {
#pragma omp sections // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
#pragma omp sections
{
#pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp simd
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp parallel
for (int i = 0; i < 10; ++i);
}
#pragma omp sections
{
#pragma omp sections // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}}
{
bar();
}
}
return foo<int>();
}

46 changes: 46 additions & 0 deletions clang/test/OpenMP/sections_ast_print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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, int N>
T tmain(T argc) {
T b = argc, c, d, e, f, g;
static T a;
// CHECK: static T a;
#pragma omp parallel
#pragma omp sections private(argc, b), firstprivate(c, d), lastprivate(d, f) reduction (-: g) nowait
{
foo();
}
// CHECK-NEXT: #pragma omp parallel
// CHECK-NEXT: #pragma omp sections private(argc,b) firstprivate(c,d) lastprivate(d,f) reduction(-: g) nowait
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: }
return T();
}

int main(int argc, char **argv) {
int b = argc, c, d, e, f, g;
static int a;
// CHECK: static int a;
#pragma omp parallel
#pragma omp sections private(argc, b), firstprivate(argv, c), lastprivate(d, f) reduction(+:g) nowait
{
foo();
}
// CHECK-NEXT: #pragma omp parallel
// CHECK-NEXT: #pragma omp sections private(argc,b) firstprivate(argv,c) lastprivate(d,f) reduction(+: g) nowait
// CHECK-NEXT: {
// CHECK-NEXT: foo();
// CHECK-NEXT: }
return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
}

#endif
335 changes: 335 additions & 0 deletions clang/test/OpenMP/sections_firstprivate_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
// 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
#pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
#pragma omp sections firstprivate(i) // expected-error {{private variable cannot be firstprivate}}
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp sections firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(i)
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel private(i) // expected-note {{defined as private}}
#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
{
foo();
}
#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
{
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
#pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(2 * 2) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(ba) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(ca) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(da) // OK
{
foo();
}
int xa;
#pragma omp parallel
#pragma omp sections firstprivate(xa) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(S2::S2s) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(S2::S2sc) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(m) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp 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 sections firstprivate(xa) // OK: may be firstprivate
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(n) firstprivate(n) // OK
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
#pragma omp sections firstprivate(i) // expected-error {{private variable cannot be firstprivate}}
{
foo();
}
v += i;
}
#pragma omp parallel private(i) // expected-note {{defined as private}}
#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
{
foo();
}
#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
{
foo();
}

return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
}
309 changes: 309 additions & 0 deletions clang/test/OpenMP/sections_lastprivate_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
// 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
#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
#pragma omp sections lastprivate(i) // expected-error {{lastprivate variable must be shared}}
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate() // expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(2 * 2) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(ba)
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
int xa;
#pragma omp parallel
#pragma omp sections lastprivate(xa) // OK
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
{
foo();
}
#pragma omp parallel
#pragma omp sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(i)
{
foo();
}
#pragma omp parallel private(xa) // expected-note {{defined as private}}
#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
{
foo();
}
#pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
{
foo();
}
#pragma omp parallel
#pragma omp sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
{
foo();
}
#pragma omp parallel
#pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
{
foo();
}
#pragma omp parallel
#pragma omp 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}}
}
271 changes: 271 additions & 0 deletions clang/test/OpenMP/sections_misc_messages.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s

void foo();

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

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

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

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

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

int x[24];

#pragma omp parallel
#pragma omp 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]++;
}
}

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

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

void test_non_identifiers() {
int i, x;

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

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

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

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

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

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

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

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

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

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

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

204 changes: 204 additions & 0 deletions clang/test/OpenMP/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 sections private // expected-error {{expected '(' after 'private'}}
{
foo();
}
#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private() // expected-error {{expected expression}}
{
foo();
}
#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp sections private(argc)
{
foo();
}
#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp sections private(e, g)
{
foo();
}
#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
{
foo();
}
#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
{
int v = 0;
int i;
#pragma omp sections private(i)
{
foo();
}
v += i;
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
{
foo();
}
#pragma omp 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 sections private // expected-error {{expected '(' after 'private'}}
{
foo();
}
#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private() // expected-error {{expected expression}}
{
foo();
}
#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp sections private(argc)
{
foo();
}
#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
{
foo();
}
#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp sections private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}
{
foo();
}
#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
{
foo();
}
#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
{
foo();
}
#pragma omp parallel
{
int i;
#pragma omp sections private(i)
{
foo();
}
}
#pragma omp parallel shared(i)
#pragma omp parallel private(i)
#pragma omp sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
{
foo();
}
#pragma omp sections private(i)
{
foo();
}

return 0;
}

413 changes: 413 additions & 0 deletions clang/test/OpenMP/sections_reduction_messages.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,7 @@ class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
void VisitOMPParallelDirective(const OMPParallelDirective *D);
void VisitOMPSimdDirective(const OMPSimdDirective *D);
void VisitOMPForDirective(const OMPForDirective *D);
void VisitOMPSectionsDirective(const OMPSectionsDirective *D);

private:
void AddDeclarationNameInfo(const Stmt *S);
Expand Down Expand Up @@ -2287,6 +2288,10 @@ void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
VisitOMPExecutableDirective(D);
}

void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
VisitOMPExecutableDirective(D);
}

void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
}
Expand Down Expand Up @@ -3965,6 +3970,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPSimdDirective");
case CXCursor_OMPForDirective:
return cxstring::createRef("OMPForDirective");
case CXCursor_OMPSectionsDirective:
return cxstring::createRef("OMPSectionsDirective");
}

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 @@ -522,6 +522,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
case Stmt::OMPForDirectiveClass:
K = CXCursor_OMPForDirective;
break;
case Stmt::OMPSectionsDirectiveClass:
K = CXCursor_OMPSectionsDirective;
break;
}

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