[OPENMP] Initial support for 'sections' directive.

llvm-svn: 211685
This commit is contained in:
Alexey Bataev 2014-06-25 11:44:49 +00:00
parent 0b2d93c4f0
commit d3f8dd2d15
31 changed files with 1895 additions and 7 deletions

View File

@ -2143,7 +2143,11 @@ enum CXCursorKind {
*/
CXCursor_OMPForDirective = 234,
CXCursor_LastStmt = CXCursor_OMPForDirective,
/** \brief OpenMP sections directive.
*/
CXCursor_OMPSectionsDirective = 235,
CXCursor_LastStmt = CXCursor_OMPSectionsDirective,
/**
* \brief Cursor that represents the translation unit itself.

View File

@ -2290,6 +2290,11 @@ DEF_TRAVERSE_STMT(OMPForDirective, {
return false;
})
DEF_TRAVERSE_STMT(OMPSectionsDirective, {
if (!TraverseOMPExecutableDirective(S))
return false;
})
// OpenMP clauses.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {

View File

@ -2312,6 +2312,11 @@ DEF_TRAVERSE_STMT(OMPForDirective, {
return false;
})
DEF_TRAVERSE_STMT(OMPSectionsDirective, {
if (!TraverseOMPExecutableDirective(S))
return false;
})
// OpenMP clauses.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {

View File

@ -365,6 +365,64 @@ public:
}
};
/// \brief This represents '#pragma omp sections' directive.
///
/// \code
/// #pragma omp sections private(a,b) reduction(+:c,d)
/// \endcode
/// In this example directive '#pragma omp sections' has clauses 'private' with
/// the variables 'a' and 'b' and 'reduction' with operator '+' and variables
/// 'c' and 'd'.
///
class OMPSectionsDirective : public OMPExecutableDirective {
friend class ASTStmtReader;
/// \brief Build directive with the given start and end location.
///
/// \param StartLoc Starting location of the directive kind.
/// \param EndLoc Ending location of the directive.
/// \param NumClauses Number of clauses.
///
OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
unsigned NumClauses)
: OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
StartLoc, EndLoc, NumClauses, 1) {}
/// \brief Build an empty directive.
///
/// \param NumClauses Number of clauses.
///
explicit OMPSectionsDirective(unsigned NumClauses)
: OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
SourceLocation(), SourceLocation(), NumClauses,
1) {}
public:
/// \brief Creates directive with a list of \a Clauses.
///
/// \param C AST context.
/// \param StartLoc Starting location of the directive kind.
/// \param EndLoc Ending Location of the directive.
/// \param Clauses List of clauses.
/// \param AssociatedStmt Statement, associated with the directive.
///
static OMPSectionsDirective *
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
/// \brief Creates an empty directive with the place for \a NumClauses
/// clauses.
///
/// \param C AST context.
/// \param NumClauses Number of clauses.
///
static OMPSectionsDirective *CreateEmpty(const ASTContext &C,
unsigned NumClauses, EmptyShell);
static bool classof(const Stmt *T) {
return T->getStmtClass() == OMPSectionsDirectiveClass;
}
};
} // end namespace clang
#endif

View File

@ -7104,6 +7104,8 @@ def err_omp_prohibited_region : Error<
"%select{|; perhaps you forget to enclose 'omp %3' directive into a parallel region?}2">;
def err_omp_prohibited_region_simd : Error<
"OpenMP constructs may not be nested inside a simd region">;
def err_omp_sections_not_compound_stmt : Error<
"the statement for '#pragma omp sections' must be a compound statement">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {

View File

@ -27,6 +27,9 @@
#ifndef OPENMP_FOR_CLAUSE
# define OPENMP_FOR_CLAUSE(Name)
#endif
#ifndef OPENMP_SECTIONS_CLAUSE
# define OPENMP_SECTIONS_CLAUSE(Name)
#endif
#ifndef OPENMP_DEFAULT_KIND
# define OPENMP_DEFAULT_KIND(Name)
#endif
@ -43,6 +46,7 @@ OPENMP_DIRECTIVE(parallel)
OPENMP_DIRECTIVE(task)
OPENMP_DIRECTIVE(simd)
OPENMP_DIRECTIVE(for)
OPENMP_DIRECTIVE(sections)
// OpenMP clauses.
OPENMP_CLAUSE(if, OMPIfClause)
@ -92,6 +96,13 @@ OPENMP_FOR_CLAUSE(schedule)
OPENMP_FOR_CLAUSE(ordered)
OPENMP_FOR_CLAUSE(nowait)
// Clauses allowed for OpenMP directive 'omp sections'.
OPENMP_SECTIONS_CLAUSE(private)
OPENMP_SECTIONS_CLAUSE(lastprivate)
OPENMP_SECTIONS_CLAUSE(firstprivate)
OPENMP_SECTIONS_CLAUSE(reduction)
OPENMP_SECTIONS_CLAUSE(nowait)
// Static attributes for 'default' clause.
OPENMP_DEFAULT_KIND(none)
OPENMP_DEFAULT_KIND(shared)
@ -113,6 +124,7 @@ OPENMP_SCHEDULE_KIND(runtime)
#undef OPENMP_DEFAULT_KIND
#undef OPENMP_DIRECTIVE
#undef OPENMP_CLAUSE
#undef OPENMP_SECTIONS_CLAUSE
#undef OPENMP_PARALLEL_CLAUSE
#undef OPENMP_SIMD_CLAUSE
#undef OPENMP_FOR_CLAUSE

View File

@ -180,3 +180,4 @@ def OMPExecutableDirective : Stmt<1>;
def OMPParallelDirective : DStmt<OMPExecutableDirective>;
def OMPSimdDirective : DStmt<OMPExecutableDirective>;
def OMPForDirective : DStmt<OMPExecutableDirective>;
def OMPSectionsDirective : DStmt<OMPExecutableDirective>;

View File

@ -7297,7 +7297,7 @@ public:
SourceLocation Loc,
ArrayRef<Expr *> VarList);
// brief Initialization of captured region for OpenMP parallel region.
// brief Initialization of captured region for OpenMP region.
void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc,
Scope *CurScope);
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
@ -7322,6 +7322,11 @@ public:
StmtResult ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt,
SourceLocation StartLoc,
SourceLocation EndLoc);
/// \brief Called on well-formed '\#pragma omp sections' after parsing
/// of the associated statement.
StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
Stmt *AStmt, SourceLocation StartLoc,
SourceLocation EndLoc);
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
Expr *Expr,

View File

@ -1342,6 +1342,7 @@ namespace clang {
STMT_OMP_PARALLEL_DIRECTIVE,
STMT_OMP_SIMD_DIRECTIVE,
STMT_OMP_FOR_DIRECTIVE,
STMT_OMP_SECTIONS_DIRECTIVE,
// ARC
EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr

View File

@ -1386,3 +1386,27 @@ OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
}
OMPSectionsDirective *OMPSectionsDirective::Create(
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
llvm::alignOf<OMPClause *>());
void *Mem =
C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
OMPSectionsDirective *Dir =
new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
Dir->setClauses(Clauses);
Dir->setAssociatedStmt(AssociatedStmt);
return Dir;
}
OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
unsigned NumClauses,
EmptyShell) {
unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
llvm::alignOf<OMPClause *>());
void *Mem =
C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
return new (Mem) OMPSectionsDirective(NumClauses);
}

View File

@ -787,6 +787,11 @@ void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) {
PrintOMPExecutableDirective(Node);
}
void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) {
Indent() << "#pragma omp sections ";
PrintOMPExecutableDirective(Node);
}
//===----------------------------------------------------------------------===//
// Expr printing methods.
//===----------------------------------------------------------------------===//

View File

@ -360,6 +360,10 @@ void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
VisitOMPExecutableDirective(S);
}
void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
VisitOMPExecutableDirective(S);
}
void StmtProfiler::VisitExpr(const Expr *S) {
VisitStmt(S);
}

View File

@ -186,6 +186,16 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
#define OPENMP_FOR_CLAUSE(Name) \
case OMPC_##Name: \
return true;
#include "clang/Basic/OpenMPKinds.def"
default:
break;
}
break;
case OMPD_sections:
switch (CKind) {
#define OPENMP_SECTIONS_CLAUSE(Name) \
case OMPC_##Name: \
return true;
#include "clang/Basic/OpenMPKinds.def"
default:
break;
@ -204,7 +214,8 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
}
bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
return DKind == OMPD_for; // TODO add next directives.
return DKind == OMPD_for ||
DKind == OMPD_sections; // TODO add next directives.
}
bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {

View File

@ -182,6 +182,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
case Stmt::OMPForDirectiveClass:
EmitOMPForDirective(cast<OMPForDirective>(*S));
break;
case Stmt::OMPSectionsDirectiveClass:
EmitOMPSectionsDirective(cast<OMPSectionsDirective>(*S));
break;
}
}

View File

@ -76,5 +76,10 @@ void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
}
void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &) {
llvm_unreachable("Not supported yet.");
llvm_unreachable("CodeGen for 'omp for' is not supported yet.");
}
void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &) {
llvm_unreachable("CodeGen for 'omp sections' is not supported yet.");
}

View File

@ -1903,6 +1903,7 @@ public:
void EmitOMPParallelDirective(const OMPParallelDirective &S);
void EmitOMPSimdDirective(const OMPSimdDirective &S);
void EmitOMPForDirective(const OMPForDirective &S);
void EmitOMPSectionsDirective(const OMPSectionsDirective &S);
//===--------------------------------------------------------------------===//
// LValue Expression Emission

View File

@ -63,6 +63,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
case OMPD_simd:
case OMPD_task:
case OMPD_for:
case OMPD_sections:
Diag(Tok, diag::err_omp_unexpected_directive)
<< getOpenMPDirectiveName(DKind);
break;
@ -77,8 +78,9 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
/// annot_pragma_openmp 'threadprivate' simple-variable-list
/// annot_pragma_openmp_end
///
/// parallel-directive:
/// annot_pragma_openmp 'parallel' {clause} annot_pragma_openmp_end
/// executable-directive:
/// annot_pragma_openmp 'parallel'|'simd'|'for'|'sections' {clause}
/// annot_pragma_openmp_end
///
StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
@ -116,7 +118,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
break;
case OMPD_parallel:
case OMPD_simd:
case OMPD_for: {
case OMPD_for:
case OMPD_sections: {
ConsumeToken();
if (isOpenMPLoopDirective(DKind))

View File

@ -910,6 +910,13 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc,
ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
break;
}
case OMPD_sections: {
Sema::CapturedParamNameType Params[] = {
std::make_pair(StringRef(), QualType()) // __context with shared vars
};
ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
break;
}
case OMPD_threadprivate:
case OMPD_task:
llvm_unreachable("OpenMP Directive is not allowed");
@ -997,6 +1004,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
case OMPD_for:
Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc);
break;
case OMPD_sections:
Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc,
EndLoc);
break;
case OMPD_threadprivate:
case OMPD_task:
llvm_unreachable("OpenMP Directive is not allowed");
@ -1567,6 +1578,32 @@ StmtResult Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses,
Clauses, AStmt);
}
StmtResult Sema::ActOnOpenMPSectionsDirective(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.
// TODO
} else {
Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
return StmtError();
}
getCurFunction()->setHasBranchProtectedScope();
return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
AStmt);
}
OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
SourceLocation StartLoc,
SourceLocation LParenLoc,

View File

@ -6429,6 +6429,16 @@ TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
return Res;
}
template <typename Derived>
StmtResult
TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
DeclarationNameInfo DirName;
getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr);
StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
getDerived().getSema().EndOpenMPDSABlock(Res.get());
return Res;
}
//===----------------------------------------------------------------------===//
// OpenMP clause transformation
//===----------------------------------------------------------------------===//

View File

@ -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
//===----------------------------------------------------------------------===//
@ -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;

View File

@ -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
//===----------------------------------------------------------------------===//

View File

@ -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:

View File

@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s
void bar();
template <class T>
void foo() {
#pragma omp parallel
@ -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}}
@ -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?}}
@ -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() {
@ -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}}
@ -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?}}
@ -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>();
}

View File

@ -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

View File

@ -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}}
}

View File

@ -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}}
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -0,0 +1,413 @@
// 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
#pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp 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
#pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp 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
#pragma omp sections reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(^ : T) // expected-error {{'T' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp 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
#pragma omp sections reduction(max : qa[1]) // expected-error 2 {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp sections reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel
#pragma omp 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 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
#pragma omp 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
#pragma omp 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 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) // expected-note 2 {{defined as private}}
#pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}}
{
foo();
}
#pragma omp parallel reduction(* : fl) // expected-note 2 {{defined as reduction}}
#pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}}
{
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
#pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp 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
#pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(~ : argc) // expected-error {{expected unqualified-id}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : argc)
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp 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
#pragma omp sections reduction(max : argv[1]) // expected-error {{expected variable name}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(- : da) // expected-error {{a reduction variable with array type 'const int [5]'}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp 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
#pragma omp sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
{
foo();
}
#pragma omp parallel
#pragma omp sections reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}}
{
foo();
}
#pragma omp parallel
#pragma omp 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 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
#pragma omp 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
#pragma omp 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 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) // expected-note {{defined as private}}
#pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}}
{
foo();
}
#pragma omp parallel reduction(* : fl) // expected-note {{defined as reduction}}
#pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}}
{
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}}
}

View File

@ -1852,6 +1852,7 @@ public:
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);
@ -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);
}
@ -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");

View File

@ -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 } };