forked from OSchip/llvm-project
OpenMP: Data-sharing attributes analysis and clause 'shared' (fixed test threadprivate_messages.cpp)
llvm-svn: 190183
This commit is contained in:
parent
b248b4a1de
commit
758e55ee58
|
@ -2346,12 +2346,17 @@ bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *C) {
|
||||||
TraverseStmt(*I);
|
TraverseStmt(*I);
|
||||||
|
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(
|
bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
OMPPrivateClause *C) {
|
|
||||||
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Derived>
|
||||||
|
bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
|
||||||
|
PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#undef PROCESS_OMP_CLAUSE_LIST
|
#undef PROCESS_OMP_CLAUSE_LIST
|
||||||
|
|
||||||
// FIXME: look at the following tricky-seeming exprs to see if we
|
// FIXME: look at the following tricky-seeming exprs to see if we
|
||||||
|
|
|
@ -249,6 +249,63 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
|
||||||
|
///
|
||||||
|
/// \code
|
||||||
|
/// #pragma omp parallel shared(a,b)
|
||||||
|
/// \endcode
|
||||||
|
/// In this example directive '#pragma omp parallel' has clause 'shared'
|
||||||
|
/// with the variables 'a' and 'b'.
|
||||||
|
///
|
||||||
|
class OMPSharedClause : public OMPClause, public OMPVarList<OMPSharedClause> {
|
||||||
|
/// \brief Build clause with number of variables \a N.
|
||||||
|
///
|
||||||
|
/// \param StartLoc Starting location of the clause.
|
||||||
|
/// \param LParenLoc Location of '('.
|
||||||
|
/// \param EndLoc Ending location of the clause.
|
||||||
|
/// \param N Number of the variables in the clause.
|
||||||
|
///
|
||||||
|
OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc, unsigned N)
|
||||||
|
: OMPClause(OMPC_shared, StartLoc, EndLoc),
|
||||||
|
OMPVarList<OMPSharedClause>(LParenLoc, N) { }
|
||||||
|
|
||||||
|
/// \brief Build an empty clause.
|
||||||
|
///
|
||||||
|
/// \param N Number of variables.
|
||||||
|
///
|
||||||
|
explicit OMPSharedClause(unsigned N)
|
||||||
|
: OMPClause(OMPC_private, SourceLocation(), SourceLocation()),
|
||||||
|
OMPVarList<OMPSharedClause>(SourceLocation(), N) { }
|
||||||
|
public:
|
||||||
|
/// \brief Creates clause with a list of variables \a VL.
|
||||||
|
///
|
||||||
|
/// \param C AST context.
|
||||||
|
/// \param StartLoc Starting location of the clause.
|
||||||
|
/// \param LParenLoc Location of '('.
|
||||||
|
/// \param EndLoc Ending location of the clause.
|
||||||
|
/// \param VL List of references to the variables.
|
||||||
|
///
|
||||||
|
static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
|
||||||
|
SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc, ArrayRef<Expr *> VL);
|
||||||
|
/// \brief Creates an empty clause with \a N variables.
|
||||||
|
///
|
||||||
|
/// \param C AST context.
|
||||||
|
/// \param N The number of variables.
|
||||||
|
///
|
||||||
|
static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
|
||||||
|
|
||||||
|
StmtRange children() {
|
||||||
|
return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
|
||||||
|
reinterpret_cast<Stmt **>(varlist_end()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool classof(const OMPClause *T) {
|
||||||
|
return T->getClauseKind() == OMPC_shared;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// AST classes for directives.
|
// AST classes for directives.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -15,7 +15,8 @@ namespace clang {
|
||||||
|
|
||||||
/// \brief The different kinds of captured statement.
|
/// \brief The different kinds of captured statement.
|
||||||
enum CapturedRegionKind {
|
enum CapturedRegionKind {
|
||||||
CR_Default
|
CR_Default,
|
||||||
|
CR_OpenMP
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
|
@ -6612,6 +6612,14 @@ def err_omp_clause_ref_type_arg : Error<
|
||||||
"arguments of OpenMP clause '%0' cannot be of reference type %1">;
|
"arguments of OpenMP clause '%0' cannot be of reference type %1">;
|
||||||
def err_omp_threadprivate_incomplete_type : Error<
|
def err_omp_threadprivate_incomplete_type : Error<
|
||||||
"threadprivate variable with incomplete type %0">;
|
"threadprivate variable with incomplete type %0">;
|
||||||
|
def err_omp_no_dsa_for_variable : Error <
|
||||||
|
"variable %0 must have explicitly specified data sharing attributes">;
|
||||||
|
def err_omp_wrong_dsa : Error<
|
||||||
|
"%0 variable cannot be %1">;
|
||||||
|
def note_omp_explicit_dsa : Note <
|
||||||
|
"defined as %0">;
|
||||||
|
def note_omp_predetermined_dsa : Note <
|
||||||
|
"predetermined as %0">;
|
||||||
} // end of OpenMP category
|
} // end of OpenMP category
|
||||||
|
|
||||||
let CategoryName = "Related Result Type Issue" in {
|
let CategoryName = "Related Result Type Issue" in {
|
||||||
|
|
|
@ -33,10 +33,12 @@ OPENMP_DIRECTIVE(task)
|
||||||
// OpenMP clauses.
|
// OpenMP clauses.
|
||||||
OPENMP_CLAUSE(default, OMPDefaultClause)
|
OPENMP_CLAUSE(default, OMPDefaultClause)
|
||||||
OPENMP_CLAUSE(private, OMPPrivateClause)
|
OPENMP_CLAUSE(private, OMPPrivateClause)
|
||||||
|
OPENMP_CLAUSE(shared, OMPSharedClause)
|
||||||
|
|
||||||
// Clauses allowed for OpenMP directives.
|
// Clauses allowed for OpenMP directives.
|
||||||
OPENMP_PARALLEL_CLAUSE(default)
|
OPENMP_PARALLEL_CLAUSE(default)
|
||||||
OPENMP_PARALLEL_CLAUSE(private)
|
OPENMP_PARALLEL_CLAUSE(private)
|
||||||
|
OPENMP_PARALLEL_CLAUSE(shared)
|
||||||
|
|
||||||
// Static attributes for 'default' clause.
|
// Static attributes for 'default' clause.
|
||||||
OPENMP_DEFAULT_KIND(none)
|
OPENMP_DEFAULT_KIND(none)
|
||||||
|
|
|
@ -91,7 +91,10 @@ public:
|
||||||
TryScope = 0x2000,
|
TryScope = 0x2000,
|
||||||
|
|
||||||
/// \brief This is the scope for a function-level C++ try or catch scope.
|
/// \brief This is the scope for a function-level C++ try or catch scope.
|
||||||
FnTryCatchScope = 0x4000
|
FnTryCatchScope = 0x4000,
|
||||||
|
|
||||||
|
/// \brief This is the scope of OpenMP executable directive
|
||||||
|
OpenMPDirectiveScope = 0x8000
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
/// The parent scope for this scope. This is null for the translation-unit
|
/// The parent scope for this scope. This is null for the translation-unit
|
||||||
|
@ -301,7 +304,12 @@ public:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Determines whether this scope is the OpenMP directive scope
|
||||||
|
bool isOpenMPDirectiveScope() const {
|
||||||
|
return (getFlags() & Scope::OpenMPDirectiveScope);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Determine whether this scope is a C++ 'try' block.
|
/// \brief Determine whether this scope is a C++ 'try' block.
|
||||||
bool isTryScope() const { return getFlags() & Scope::TryScope; }
|
bool isTryScope() const { return getFlags() & Scope::TryScope; }
|
||||||
|
|
||||||
|
|
|
@ -567,6 +567,8 @@ public:
|
||||||
switch (CapRegionKind) {
|
switch (CapRegionKind) {
|
||||||
case CR_Default:
|
case CR_Default:
|
||||||
return "default captured statement";
|
return "default captured statement";
|
||||||
|
case CR_OpenMP:
|
||||||
|
return "OpenMP region";
|
||||||
}
|
}
|
||||||
llvm_unreachable("Invalid captured region kind!");
|
llvm_unreachable("Invalid captured region kind!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6886,6 +6886,20 @@ public:
|
||||||
void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
|
void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
|
||||||
unsigned SpellingListIndex, bool IsPackExpansion);
|
unsigned SpellingListIndex, bool IsPackExpansion);
|
||||||
|
|
||||||
|
// OpenMP directives and clauses.
|
||||||
|
private:
|
||||||
|
void *VarDataSharingAttributesStack;
|
||||||
|
/// \brief Initialization of data-sharing attributes stack.
|
||||||
|
void InitDataSharingAttributesStack();
|
||||||
|
void DestroyDataSharingAttributesStack();
|
||||||
|
public:
|
||||||
|
/// \brief Called on start of new data sharing attribute block.
|
||||||
|
void StartOpenMPDSABlock(OpenMPDirectiveKind K,
|
||||||
|
const DeclarationNameInfo &DirName,
|
||||||
|
Scope *CurScope);
|
||||||
|
/// \brief Called on end of data sharing attribute block.
|
||||||
|
void EndOpenMPDSABlock(Stmt *CurDirective);
|
||||||
|
|
||||||
// OpenMP directives and clauses.
|
// OpenMP directives and clauses.
|
||||||
/// \brief Called on correct id-expression from the '#pragma omp
|
/// \brief Called on correct id-expression from the '#pragma omp
|
||||||
/// threadprivate'.
|
/// threadprivate'.
|
||||||
|
@ -6936,6 +6950,11 @@ public:
|
||||||
SourceLocation StartLoc,
|
SourceLocation StartLoc,
|
||||||
SourceLocation LParenLoc,
|
SourceLocation LParenLoc,
|
||||||
SourceLocation EndLoc);
|
SourceLocation EndLoc);
|
||||||
|
/// \brief Called on well-formed 'shared' clause.
|
||||||
|
OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
|
||||||
|
SourceLocation StartLoc,
|
||||||
|
SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc);
|
||||||
|
|
||||||
/// \brief The kind of conversion being performed.
|
/// \brief The kind of conversion being performed.
|
||||||
enum CheckedConversionKind {
|
enum CheckedConversionKind {
|
||||||
|
|
|
@ -1111,6 +1111,16 @@ bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StmtRange OMPClause::children() {
|
||||||
|
switch(getClauseKind()) {
|
||||||
|
default : break;
|
||||||
|
#define OPENMP_CLAUSE(Name, Class) \
|
||||||
|
case OMPC_ ## Name : return static_cast<Class *>(this)->children();
|
||||||
|
#include "clang/Basic/OpenMPKinds.def"
|
||||||
|
}
|
||||||
|
llvm_unreachable("unknown OMPClause");
|
||||||
|
}
|
||||||
|
|
||||||
OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C,
|
OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C,
|
||||||
SourceLocation StartLoc,
|
SourceLocation StartLoc,
|
||||||
SourceLocation LParenLoc,
|
SourceLocation LParenLoc,
|
||||||
|
@ -1131,6 +1141,26 @@ OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
|
||||||
return new (Mem) OMPPrivateClause(N);
|
return new (Mem) OMPPrivateClause(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
|
||||||
|
SourceLocation StartLoc,
|
||||||
|
SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc,
|
||||||
|
ArrayRef<Expr *> VL) {
|
||||||
|
void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * VL.size(),
|
||||||
|
llvm::alignOf<OMPSharedClause>());
|
||||||
|
OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
|
||||||
|
EndLoc, VL.size());
|
||||||
|
Clause->setVarRefs(VL);
|
||||||
|
return Clause;
|
||||||
|
}
|
||||||
|
|
||||||
|
OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
|
||||||
|
unsigned N) {
|
||||||
|
void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * N,
|
||||||
|
llvm::alignOf<OMPSharedClause>());
|
||||||
|
return new (Mem) OMPSharedClause(N);
|
||||||
|
}
|
||||||
|
|
||||||
void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
|
void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
|
||||||
assert(Clauses.size() == this->Clauses.size() &&
|
assert(Clauses.size() == this->Clauses.size() &&
|
||||||
"Number of clauses is not the same as the preallocated buffer");
|
"Number of clauses is not the same as the preallocated buffer");
|
||||||
|
|
|
@ -614,6 +614,14 @@ void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
|
||||||
|
if (!Node->varlist_empty()) {
|
||||||
|
OS << "shared";
|
||||||
|
PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, Node, '(')
|
||||||
|
OS << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#undef PROCESS_OMP_CLAUSE_LIST
|
#undef PROCESS_OMP_CLAUSE_LIST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,6 +272,9 @@ void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
|
||||||
void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
|
void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
|
||||||
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
||||||
}
|
}
|
||||||
|
void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
|
||||||
|
PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)
|
||||||
|
}
|
||||||
#undef PROCESS_OMP_CLAUSE_LIST
|
#undef PROCESS_OMP_CLAUSE_LIST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,10 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
|
||||||
case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break;
|
case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break;
|
||||||
case Stmt::GCCAsmStmtClass: // Intentional fall-through.
|
case Stmt::GCCAsmStmtClass: // Intentional fall-through.
|
||||||
case Stmt::MSAsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break;
|
case Stmt::MSAsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break;
|
||||||
case Stmt::CapturedStmtClass:
|
case Stmt::CapturedStmtClass: {
|
||||||
EmitCapturedStmt(cast<CapturedStmt>(*S), CR_Default);
|
const CapturedStmt *CS = cast<CapturedStmt>(S);
|
||||||
|
EmitCapturedStmt(*CS, CS->getCapturedRegionKind());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Stmt::ObjCAtTryStmtClass:
|
case Stmt::ObjCAtTryStmtClass:
|
||||||
EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
|
EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
|
||||||
|
|
|
@ -84,11 +84,14 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
|
||||||
SmallVector<OMPClause *, 5> Clauses;
|
SmallVector<OMPClause *, 5> Clauses;
|
||||||
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, NUM_OPENMP_CLAUSES>
|
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, NUM_OPENMP_CLAUSES>
|
||||||
FirstClauses(NUM_OPENMP_CLAUSES);
|
FirstClauses(NUM_OPENMP_CLAUSES);
|
||||||
const unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope;
|
const unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
|
||||||
|
Scope::OpenMPDirectiveScope;
|
||||||
SourceLocation Loc = ConsumeToken(), EndLoc;
|
SourceLocation Loc = ConsumeToken(), EndLoc;
|
||||||
OpenMPDirectiveKind DKind = Tok.isAnnotation() ?
|
OpenMPDirectiveKind DKind = Tok.isAnnotation() ?
|
||||||
OMPD_unknown :
|
OMPD_unknown :
|
||||||
getOpenMPDirectiveKind(PP.getSpelling(Tok));
|
getOpenMPDirectiveKind(PP.getSpelling(Tok));
|
||||||
|
// Name of critical directive.
|
||||||
|
DeclarationNameInfo DirName;
|
||||||
StmtResult Directive = StmtError();
|
StmtResult Directive = StmtError();
|
||||||
|
|
||||||
switch (DKind) {
|
switch (DKind) {
|
||||||
|
@ -111,6 +114,9 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
|
||||||
break;
|
break;
|
||||||
case OMPD_parallel: {
|
case OMPD_parallel: {
|
||||||
ConsumeToken();
|
ConsumeToken();
|
||||||
|
|
||||||
|
Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope());
|
||||||
|
|
||||||
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
|
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
|
||||||
OpenMPClauseKind CKind = Tok.isAnnotation() ?
|
OpenMPClauseKind CKind = Tok.isAnnotation() ?
|
||||||
OMPC_unknown :
|
OMPC_unknown :
|
||||||
|
@ -138,7 +144,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
|
||||||
{
|
{
|
||||||
// The body is a block scope like in Lambdas and Blocks.
|
// The body is a block scope like in Lambdas and Blocks.
|
||||||
Sema::CompoundScopeRAII CompoundScope(Actions);
|
Sema::CompoundScopeRAII CompoundScope(Actions);
|
||||||
Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_Default, 1);
|
Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_OpenMP, 1);
|
||||||
Actions.ActOnStartOfCompoundStmt();
|
Actions.ActOnStartOfCompoundStmt();
|
||||||
// Parse statement
|
// Parse statement
|
||||||
AssociatedStmt = ParseStatement();
|
AssociatedStmt = ParseStatement();
|
||||||
|
@ -157,6 +163,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
|
||||||
Loc, EndLoc);
|
Loc, EndLoc);
|
||||||
|
|
||||||
// Exit scope.
|
// Exit scope.
|
||||||
|
Actions.EndOpenMPDSABlock(Directive.get());
|
||||||
OMPDirectiveScope.Exit();
|
OMPDirectiveScope.Exit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -245,7 +252,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
|
||||||
/// \brief Parsing of OpenMP clauses.
|
/// \brief Parsing of OpenMP clauses.
|
||||||
///
|
///
|
||||||
/// clause:
|
/// clause:
|
||||||
/// default-clause|private-clause
|
/// default-clause|private-clause|shared-clause
|
||||||
///
|
///
|
||||||
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
|
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
|
||||||
OpenMPClauseKind CKind, bool FirstClause) {
|
OpenMPClauseKind CKind, bool FirstClause) {
|
||||||
|
@ -271,6 +278,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
|
||||||
Clause = ParseOpenMPSimpleClause(CKind);
|
Clause = ParseOpenMPSimpleClause(CKind);
|
||||||
break;
|
break;
|
||||||
case OMPC_private:
|
case OMPC_private:
|
||||||
|
case OMPC_shared:
|
||||||
Clause = ParseOpenMPVarListClause(CKind);
|
Clause = ParseOpenMPVarListClause(CKind);
|
||||||
break;
|
break;
|
||||||
case OMPC_unknown:
|
case OMPC_unknown:
|
||||||
|
@ -322,6 +330,8 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
|
||||||
///
|
///
|
||||||
/// private-clause:
|
/// private-clause:
|
||||||
/// 'private' '(' list ')'
|
/// 'private' '(' list ')'
|
||||||
|
/// shared-clause:
|
||||||
|
/// 'shared' '(' list ')'
|
||||||
///
|
///
|
||||||
OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
|
OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
|
||||||
SourceLocation Loc = Tok.getLocation();
|
SourceLocation Loc = Tok.getLocation();
|
||||||
|
|
|
@ -90,7 +90,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
|
||||||
AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
|
AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
|
||||||
NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
|
NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
|
||||||
CurrentInstantiationScope(0), TyposCorrected(0),
|
CurrentInstantiationScope(0), TyposCorrected(0),
|
||||||
AnalysisWarnings(*this), CurScope(0), Ident_super(0), Ident___float128(0)
|
AnalysisWarnings(*this), VarDataSharingAttributesStack(0), CurScope(0),
|
||||||
|
Ident_super(0), Ident___float128(0)
|
||||||
{
|
{
|
||||||
TUScope = 0;
|
TUScope = 0;
|
||||||
|
|
||||||
|
@ -113,6 +114,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
|
||||||
false, 0, false));
|
false, 0, false));
|
||||||
|
|
||||||
FunctionScopes.push_back(new FunctionScopeInfo(Diags));
|
FunctionScopes.push_back(new FunctionScopeInfo(Diags));
|
||||||
|
|
||||||
|
// Initilization of data sharing attributes stack for OpenMP
|
||||||
|
InitDataSharingAttributesStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::Initialize() {
|
void Sema::Initialize() {
|
||||||
|
@ -199,6 +203,9 @@ Sema::~Sema() {
|
||||||
// If Sema's ExternalSource is the multiplexer - we own it.
|
// If Sema's ExternalSource is the multiplexer - we own it.
|
||||||
if (isMultiplexExternalSource)
|
if (isMultiplexExternalSource)
|
||||||
delete ExternalSource;
|
delete ExternalSource;
|
||||||
|
|
||||||
|
// Destroys data sharing attributes stack for OpenMP
|
||||||
|
DestroyDataSharingAttributesStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// makeUnavailableInSystemHeader - There is an error in the current
|
/// makeUnavailableInSystemHeader - There is an error in the current
|
||||||
|
|
|
@ -27,6 +27,325 @@
|
||||||
#include "clang/Sema/ScopeInfo.h"
|
#include "clang/Sema/ScopeInfo.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Stack of data-sharing attributes for variables
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// \brief Default data sharing attributes, which can be applied to directive.
|
||||||
|
enum DefaultDataSharingAttributes {
|
||||||
|
DSA_unspecified = 0, /// \brief Data sharing attribute not specified.
|
||||||
|
DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'.
|
||||||
|
DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'.
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Stack for tracking declarations used in OpenMP directives and
|
||||||
|
/// clauses and their data-sharing attributes.
|
||||||
|
class DSAStackTy {
|
||||||
|
public:
|
||||||
|
struct DSAVarData {
|
||||||
|
OpenMPDirectiveKind DKind;
|
||||||
|
OpenMPClauseKind CKind;
|
||||||
|
DeclRefExpr *RefExpr;
|
||||||
|
DSAVarData() : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(0) { }
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
struct DSAInfo {
|
||||||
|
OpenMPClauseKind Attributes;
|
||||||
|
DeclRefExpr *RefExpr;
|
||||||
|
};
|
||||||
|
typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy;
|
||||||
|
|
||||||
|
struct SharingMapTy {
|
||||||
|
DeclSAMapTy SharingMap;
|
||||||
|
DefaultDataSharingAttributes DefaultAttr;
|
||||||
|
OpenMPDirectiveKind Directive;
|
||||||
|
DeclarationNameInfo DirectiveName;
|
||||||
|
Scope *CurScope;
|
||||||
|
SharingMapTy(OpenMPDirectiveKind DKind,
|
||||||
|
const DeclarationNameInfo &Name,
|
||||||
|
Scope *CurScope)
|
||||||
|
: SharingMap(), DefaultAttr(DSA_unspecified), Directive(DKind),
|
||||||
|
DirectiveName(Name), CurScope(CurScope) { }
|
||||||
|
SharingMapTy()
|
||||||
|
: SharingMap(), DefaultAttr(DSA_unspecified),
|
||||||
|
Directive(OMPD_unknown), DirectiveName(),
|
||||||
|
CurScope(0) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef SmallVector<SharingMapTy, 64> StackTy;
|
||||||
|
|
||||||
|
/// \brief Stack of used declaration and their data-sharing attributes.
|
||||||
|
StackTy Stack;
|
||||||
|
Sema &Actions;
|
||||||
|
|
||||||
|
typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator;
|
||||||
|
|
||||||
|
DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D);
|
||||||
|
public:
|
||||||
|
explicit DSAStackTy(Sema &S) : Stack(1), Actions(S) { }
|
||||||
|
|
||||||
|
void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName,
|
||||||
|
Scope *CurScope) {
|
||||||
|
Stack.push_back(SharingMapTy(DKind, DirName, CurScope));
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop() {
|
||||||
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!");
|
||||||
|
Stack.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Adds explicit data sharing attribute to the specified declaration.
|
||||||
|
void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A);
|
||||||
|
|
||||||
|
/// \brief Checks if the variable is a local for OpenMP region.
|
||||||
|
bool isOpenMPLocal(VarDecl *D);
|
||||||
|
|
||||||
|
/// \brief Returns data sharing attributes from top of the stack for the
|
||||||
|
/// specified declaration.
|
||||||
|
DSAVarData getTopDSA(VarDecl *D);
|
||||||
|
/// \brief Returns data-sharing attributes for the specified declaration.
|
||||||
|
DSAVarData getImplicitDSA(VarDecl *D);
|
||||||
|
|
||||||
|
/// \brief Returns currently analyzed directive.
|
||||||
|
OpenMPDirectiveKind getCurrentDirective() const {
|
||||||
|
return Stack.back().Directive;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Set default data sharing attribute to none.
|
||||||
|
void setDefaultDSANone() { Stack.back().DefaultAttr = DSA_none; }
|
||||||
|
/// \brief Set default data sharing attribute to shared.
|
||||||
|
void setDefaultDSAShared() { Stack.back().DefaultAttr = DSA_shared; }
|
||||||
|
|
||||||
|
DefaultDataSharingAttributes getDefaultDSA() const {
|
||||||
|
return Stack.back().DefaultAttr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scope *getCurScope() { return Stack.back().CurScope; }
|
||||||
|
};
|
||||||
|
} // end anonymous namespace.
|
||||||
|
|
||||||
|
DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
|
||||||
|
VarDecl *D) {
|
||||||
|
DSAVarData DVar;
|
||||||
|
if (Iter == Stack.rend() - 1) {
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a region but not in construct]
|
||||||
|
// File-scope or namespace-scope variables referenced in called routines
|
||||||
|
// in the region are shared unless they appear in a threadprivate
|
||||||
|
// directive.
|
||||||
|
// TODO
|
||||||
|
if (!D->isFunctionOrMethodVarDecl())
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
DVar.DKind = Iter->Directive;
|
||||||
|
// Explicitly specified attributes and local variables with predetermined
|
||||||
|
// attributes.
|
||||||
|
if (Iter->SharingMap.count(D)) {
|
||||||
|
DVar.RefExpr = Iter->SharingMap[D].RefExpr;
|
||||||
|
DVar.CKind = Iter->SharingMap[D].Attributes;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, implicitly determined, p.1]
|
||||||
|
// In a parallel or task construct, the data-sharing attributes of these
|
||||||
|
// variables are determined by the default clause, if present.
|
||||||
|
switch (Iter->DefaultAttr) {
|
||||||
|
case DSA_shared:
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
case DSA_none:
|
||||||
|
return DVar;
|
||||||
|
case DSA_unspecified:
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, implicitly determined, p.2]
|
||||||
|
// In a parallel construct, if no default clause is present, these
|
||||||
|
// variables are shared.
|
||||||
|
if (DVar.DKind == OMPD_parallel) {
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, implicitly determined, p.4]
|
||||||
|
// In a task construct, if no default clause is present, a variable that in
|
||||||
|
// the enclosing context is determined to be shared by all implicit tasks
|
||||||
|
// bound to the current team is shared.
|
||||||
|
// TODO
|
||||||
|
if (DVar.DKind == OMPD_task) {
|
||||||
|
DSAVarData DVarTemp;
|
||||||
|
for (StackTy::reverse_iterator I = Iter + 1,
|
||||||
|
EE = Stack.rend() - 1;
|
||||||
|
I != EE; ++I) {
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, implicitly determined, p.6]
|
||||||
|
// In a task construct, if no default clause is present, a variable
|
||||||
|
// whose data-sharing attribute is not determined by the rules above is
|
||||||
|
// firstprivate.
|
||||||
|
DVarTemp = getDSA(I, D);
|
||||||
|
if (DVarTemp.CKind != OMPC_shared) {
|
||||||
|
DVar.RefExpr = 0;
|
||||||
|
DVar.DKind = OMPD_task;
|
||||||
|
DVar.CKind = OMPC_unknown;
|
||||||
|
// TODO: should return OMPC_firstprivate
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
if (I->Directive == OMPD_parallel) break;
|
||||||
|
}
|
||||||
|
DVar.DKind = OMPD_task;
|
||||||
|
// TODO: Should return OMPC_firstprivate instead of OMPC_unknown.
|
||||||
|
DVar.CKind =
|
||||||
|
(DVarTemp.CKind == OMPC_unknown) ? OMPC_unknown : OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, implicitly determined, p.3]
|
||||||
|
// For constructs other than task, if no default clause is present, these
|
||||||
|
// variables inherit their data-sharing attributes from the enclosing
|
||||||
|
// context.
|
||||||
|
return getDSA(Iter + 1, D);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {
|
||||||
|
if (A == OMPC_threadprivate) {
|
||||||
|
Stack[0].SharingMap[D].Attributes = A;
|
||||||
|
Stack[0].SharingMap[D].RefExpr = E;
|
||||||
|
} else {
|
||||||
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");
|
||||||
|
Stack.back().SharingMap[D].Attributes = A;
|
||||||
|
Stack.back().SharingMap[D].RefExpr = E;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DSAStackTy::isOpenMPLocal(VarDecl *D) {
|
||||||
|
Scope *CurScope = getCurScope();
|
||||||
|
while (CurScope && !CurScope->isDeclScope(D))
|
||||||
|
CurScope = CurScope->getParent();
|
||||||
|
while (CurScope && !CurScope->isOpenMPDirectiveScope())
|
||||||
|
CurScope = CurScope->getParent();
|
||||||
|
bool isOpenMPLocal = !!CurScope;
|
||||||
|
if (!isOpenMPLocal) {
|
||||||
|
CurScope = getCurScope();
|
||||||
|
while (CurScope && !CurScope->isOpenMPDirectiveScope())
|
||||||
|
CurScope = CurScope->getParent();
|
||||||
|
isOpenMPLocal =
|
||||||
|
CurScope &&
|
||||||
|
isa<CapturedDecl>(D->getDeclContext()) &&
|
||||||
|
static_cast<DeclContext *>(
|
||||||
|
CurScope->getFnParent()->getEntity())->Encloses(D->getDeclContext());
|
||||||
|
}
|
||||||
|
return isOpenMPLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) {
|
||||||
|
DSAVarData DVar;
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, predetermined, p.1]
|
||||||
|
// Variables appearing in threadprivate directives are threadprivate.
|
||||||
|
if (D->getTLSKind() != VarDecl::TLS_None) {
|
||||||
|
DVar.CKind = OMPC_threadprivate;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
if (Stack[0].SharingMap.count(D)) {
|
||||||
|
DVar.RefExpr = Stack[0].SharingMap[D].RefExpr;
|
||||||
|
DVar.CKind = OMPC_threadprivate;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, predetermined, p.1]
|
||||||
|
// Variables with automatic storage duration that are declared in a scope
|
||||||
|
// inside the construct are private.
|
||||||
|
if (isOpenMPLocal(D) && D->isLocalVarDecl() &&
|
||||||
|
(D->getStorageClass() == SC_Auto ||
|
||||||
|
D->getStorageClass() == SC_None)) {
|
||||||
|
DVar.CKind = OMPC_private;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, predetermined, p.4]
|
||||||
|
// Static data memebers are shared.
|
||||||
|
if (D->isStaticDataMember()) {
|
||||||
|
// Variables with const-qualified type having no mutable member may be
|
||||||
|
// listed in a firstprivate clause, even if they are static data members.
|
||||||
|
// TODO:
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
QualType Type = D->getType().getNonReferenceType().getCanonicalType();
|
||||||
|
bool IsConstant = Type.isConstant(Actions.getASTContext());
|
||||||
|
while (Type->isArrayType()) {
|
||||||
|
QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType();
|
||||||
|
Type = ElemType.getNonReferenceType().getCanonicalType();
|
||||||
|
}
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, predetermined, p.6]
|
||||||
|
// Variables with const qualified type having no mutable member are
|
||||||
|
// shared.
|
||||||
|
CXXRecordDecl *RD = Actions.getLangOpts().CPlusPlus ?
|
||||||
|
Type->getAsCXXRecordDecl() : 0;
|
||||||
|
if (IsConstant &&
|
||||||
|
!(Actions.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) {
|
||||||
|
// Variables with const-qualified type having no mutable member may be
|
||||||
|
// listed in a firstprivate clause, even if they are static data members.
|
||||||
|
// TODO
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct, C/C++, predetermined, p.7]
|
||||||
|
// Variables with static storage duration that are declared in a scope
|
||||||
|
// inside the construct are shared.
|
||||||
|
if (isOpenMPLocal(D) && D->isStaticLocal()) {
|
||||||
|
DVar.CKind = OMPC_shared;
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicitly specified attributes and local variables with predetermined
|
||||||
|
// attributes.
|
||||||
|
if (Stack.back().SharingMap.count(D)) {
|
||||||
|
DVar.RefExpr = Stack.back().SharingMap[D].RefExpr;
|
||||||
|
DVar.CKind = Stack.back().SharingMap[D].Attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) {
|
||||||
|
return getDSA(Stack.rbegin() + 1, D);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sema::InitDataSharingAttributesStack() {
|
||||||
|
VarDataSharingAttributesStack = new DSAStackTy(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack)
|
||||||
|
|
||||||
|
void Sema::DestroyDataSharingAttributesStack() {
|
||||||
|
delete DSAStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,
|
||||||
|
const DeclarationNameInfo &DirName,
|
||||||
|
Scope *CurScope) {
|
||||||
|
DSAStack->push(DKind, DirName, CurScope);
|
||||||
|
PushExpressionEvaluationContext(PotentiallyEvaluated);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sema::EndOpenMPDSABlock(Stmt *CurDirective) {
|
||||||
|
DSAStack->pop();
|
||||||
|
DiscardCleanupsInEvaluationContext();
|
||||||
|
PopExpressionEvaluationContext();
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class VarDeclFilterCCC : public CorrectionCandidateCallback {
|
class VarDeclFilterCCC : public CorrectionCandidateCallback {
|
||||||
|
@ -130,6 +449,7 @@ ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope,
|
||||||
|
|
||||||
QualType ExprType = VD->getType().getNonReferenceType();
|
QualType ExprType = VD->getType().getNonReferenceType();
|
||||||
ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_RValue, Id.getLoc());
|
ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_RValue, Id.getLoc());
|
||||||
|
DSAStack->addDSA(VD, cast<DeclRefExpr>(DE.get()), OMPC_threadprivate);
|
||||||
return DE;
|
return DE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,12 +512,93 @@ OMPThreadPrivateDecl *Sema::CheckOMPThreadPrivateDecl(
|
||||||
Loc, Vars);
|
Loc, Vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> {
|
||||||
|
DSAStackTy *Stack;
|
||||||
|
Sema &Actions;
|
||||||
|
bool ErrorFound;
|
||||||
|
CapturedStmt *CS;
|
||||||
|
public:
|
||||||
|
void VisitDeclRefExpr(DeclRefExpr *E) {
|
||||||
|
if(VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
|
||||||
|
if (VD->isImplicit() && VD->hasAttr<UnusedAttr>()) return;
|
||||||
|
// Skip internally declared variables.
|
||||||
|
if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) return;
|
||||||
|
|
||||||
|
SourceLocation ELoc = E->getExprLoc();
|
||||||
|
|
||||||
|
OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
|
||||||
|
DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD);
|
||||||
|
if (DVar.CKind != OMPC_unknown) {
|
||||||
|
if (DKind == OMPD_task && DVar.CKind != OMPC_shared &&
|
||||||
|
DVar.CKind != OMPC_threadprivate && !DVar.RefExpr)
|
||||||
|
// TODO: should be marked as firstprivate.
|
||||||
|
;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// The default(none) clause requires that each variable that is referenced
|
||||||
|
// in the construct, and does not have a predetermined data-sharing
|
||||||
|
// attribute, must have its data-sharing attribute explicitly determined
|
||||||
|
// by being listed in a data-sharing attribute clause.
|
||||||
|
if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none &&
|
||||||
|
(DKind == OMPD_parallel || DKind == OMPD_task)) {
|
||||||
|
ErrorFound = true;
|
||||||
|
Actions.Diag(ELoc, diag::err_omp_no_dsa_for_variable) << VD;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.3.6, Restrictions, p.2]
|
||||||
|
// A list item that appears in a reduction clause of the innermost
|
||||||
|
// enclosing worksharing or parallel construct may not be accessed in an
|
||||||
|
// explicit task.
|
||||||
|
// TODO:
|
||||||
|
|
||||||
|
// Define implicit data-sharing attributes for task.
|
||||||
|
DVar = Stack->getImplicitDSA(VD);
|
||||||
|
if (DKind == OMPD_task && DVar.CKind != OMPC_shared) {
|
||||||
|
// TODO: should be marked as firstprivate.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void VisitOMPExecutableDirective(OMPExecutableDirective *S) {
|
||||||
|
for (ArrayRef<OMPClause *>::iterator I = S->clauses().begin(),
|
||||||
|
E = S->clauses().end();
|
||||||
|
I != E; ++I)
|
||||||
|
if (OMPClause *C = *I)
|
||||||
|
for (StmtRange R = C->children(); R; ++R)
|
||||||
|
if (Stmt *Child = *R)
|
||||||
|
Visit(Child);
|
||||||
|
}
|
||||||
|
void VisitStmt(Stmt *S) {
|
||||||
|
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end();
|
||||||
|
I != E; ++I)
|
||||||
|
if (Stmt *Child = *I)
|
||||||
|
if (!isa<OMPExecutableDirective>(Child))
|
||||||
|
Visit(Child);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isErrorFound() { return ErrorFound; }
|
||||||
|
|
||||||
|
DSAAttrChecker(DSAStackTy *S, Sema &Actions, CapturedStmt *CS)
|
||||||
|
: Stack(S), Actions(Actions), ErrorFound(false), CS(CS) { }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
|
StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
|
||||||
ArrayRef<OMPClause *> Clauses,
|
ArrayRef<OMPClause *> Clauses,
|
||||||
Stmt *AStmt,
|
Stmt *AStmt,
|
||||||
SourceLocation StartLoc,
|
SourceLocation StartLoc,
|
||||||
SourceLocation EndLoc) {
|
SourceLocation EndLoc) {
|
||||||
|
assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
||||||
|
|
||||||
StmtResult Res = StmtError();
|
StmtResult Res = StmtError();
|
||||||
|
|
||||||
|
// Check default data sharing attributes for referenced variables.
|
||||||
|
DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt));
|
||||||
|
DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt());
|
||||||
|
if (DSAChecker.isErrorFound())
|
||||||
|
return StmtError();
|
||||||
|
|
||||||
switch (Kind) {
|
switch (Kind) {
|
||||||
case OMPD_parallel:
|
case OMPD_parallel:
|
||||||
Res = ActOnOpenMPParallelDirective(Clauses, AStmt, StartLoc, EndLoc);
|
Res = ActOnOpenMPParallelDirective(Clauses, AStmt, StartLoc, EndLoc);
|
||||||
|
@ -231,11 +632,12 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
|
||||||
OMPClause *Res = 0;
|
OMPClause *Res = 0;
|
||||||
switch (Kind) {
|
switch (Kind) {
|
||||||
case OMPC_default:
|
case OMPC_default:
|
||||||
Res = ActOnOpenMPDefaultClause(
|
Res =
|
||||||
static_cast<OpenMPDefaultClauseKind>(Argument),
|
ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument),
|
||||||
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
|
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
|
||||||
break;
|
break;
|
||||||
case OMPC_private:
|
case OMPC_private:
|
||||||
|
case OMPC_shared:
|
||||||
case OMPC_threadprivate:
|
case OMPC_threadprivate:
|
||||||
case OMPC_unknown:
|
case OMPC_unknown:
|
||||||
case NUM_OPENMP_CLAUSES:
|
case NUM_OPENMP_CLAUSES:
|
||||||
|
@ -272,6 +674,16 @@ OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind,
|
||||||
<< Values << getOpenMPClauseName(OMPC_default);
|
<< Values << getOpenMPClauseName(OMPC_default);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
switch (Kind) {
|
||||||
|
case OMPC_DEFAULT_none:
|
||||||
|
DSAStack->setDefaultDSANone();
|
||||||
|
break;
|
||||||
|
case OMPC_DEFAULT_shared:
|
||||||
|
DSAStack->setDefaultDSAShared();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc,
|
return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc,
|
||||||
EndLoc);
|
EndLoc);
|
||||||
}
|
}
|
||||||
|
@ -286,6 +698,9 @@ OMPClause *Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
|
||||||
case OMPC_private:
|
case OMPC_private:
|
||||||
Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
||||||
break;
|
break;
|
||||||
|
case OMPC_shared:
|
||||||
|
Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc);
|
||||||
|
break;
|
||||||
case OMPC_default:
|
case OMPC_default:
|
||||||
case OMPC_threadprivate:
|
case OMPC_threadprivate:
|
||||||
case OMPC_unknown:
|
case OMPC_unknown:
|
||||||
|
@ -396,6 +811,29 @@ OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct]
|
||||||
|
// Variables with the predetermined data-sharing attributes may not be
|
||||||
|
// listed in data-sharing attributes clauses, except for the cases
|
||||||
|
// listed below. For these exceptions only, listing a predetermined
|
||||||
|
// variable in a data-sharing attribute clause is allowed and overrides
|
||||||
|
// the variable's predetermined data-sharing attributes.
|
||||||
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);
|
||||||
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) {
|
||||||
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
||||||
|
<< getOpenMPClauseName(DVar.CKind)
|
||||||
|
<< getOpenMPClauseName(OMPC_private);
|
||||||
|
if (DVar.RefExpr) {
|
||||||
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
||||||
|
<< getOpenMPClauseName(DVar.CKind);
|
||||||
|
} else {
|
||||||
|
Diag(VD->getLocation(), diag::note_omp_predetermined_dsa)
|
||||||
|
<< getOpenMPClauseName(DVar.CKind);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSAStack->addDSA(VD, DE, OMPC_private);
|
||||||
Vars.push_back(DE);
|
Vars.push_back(DE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,3 +842,65 @@ OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
|
||||||
return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
|
||||||
|
SourceLocation StartLoc,
|
||||||
|
SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc) {
|
||||||
|
SmallVector<Expr *, 8> Vars;
|
||||||
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();
|
||||||
|
I != E; ++I) {
|
||||||
|
if (*I && isa<DependentScopeDeclRefExpr>(*I)) {
|
||||||
|
// It will be analyzed later.
|
||||||
|
Vars.push_back(*I);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceLocation ELoc = (*I)->getExprLoc();
|
||||||
|
// OpenMP [2.1, C/C++]
|
||||||
|
// A list item is a variable name.
|
||||||
|
// OpenMP [2.9.3.4, Restrictions, p.1]
|
||||||
|
// A variable that is part of another variable (as an array or
|
||||||
|
// structure element) cannot appear in a private clause.
|
||||||
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(*I);
|
||||||
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
||||||
|
Diag(ELoc, diag::err_omp_expected_var_name)
|
||||||
|
<< (*I)->getSourceRange();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Decl *D = DE->getDecl();
|
||||||
|
VarDecl *VD = cast<VarDecl>(D);
|
||||||
|
|
||||||
|
QualType Type = VD->getType();
|
||||||
|
if (Type->isDependentType() || Type->isInstantiationDependentType()) {
|
||||||
|
// It will be analyzed later.
|
||||||
|
Vars.push_back(DE);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
||||||
|
// in a Construct]
|
||||||
|
// Variables with the predetermined data-sharing attributes may not be
|
||||||
|
// listed in data-sharing attributes clauses, except for the cases
|
||||||
|
// listed below. For these exceptions only, listing a predetermined
|
||||||
|
// variable in a data-sharing attribute clause is allowed and overrides
|
||||||
|
// the variable's predetermined data-sharing attributes.
|
||||||
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);
|
||||||
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && DVar.RefExpr) {
|
||||||
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
||||||
|
<< getOpenMPClauseName(DVar.CKind)
|
||||||
|
<< getOpenMPClauseName(OMPC_shared);
|
||||||
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
||||||
|
<< getOpenMPClauseName(DVar.CKind);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSAStack->addDSA(VD, DE, OMPC_shared);
|
||||||
|
Vars.push_back(DE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Vars.empty()) return 0;
|
||||||
|
|
||||||
|
return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef DSAStack
|
||||||
|
|
|
@ -1312,6 +1312,14 @@ public:
|
||||||
EndLoc);
|
EndLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
|
||||||
|
SourceLocation StartLoc,
|
||||||
|
SourceLocation LParenLoc,
|
||||||
|
SourceLocation EndLoc) {
|
||||||
|
return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
|
||||||
|
EndLoc);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Rebuild the operand to an Objective-C \@synchronized statement.
|
/// \brief Rebuild the operand to an Objective-C \@synchronized statement.
|
||||||
///
|
///
|
||||||
/// By default, performs semantic analysis to build the new statement.
|
/// By default, performs semantic analysis to build the new statement.
|
||||||
|
@ -6254,33 +6262,44 @@ TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
StmtResult
|
StmtResult
|
||||||
TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
|
TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
|
||||||
|
DeclarationNameInfo DirName;
|
||||||
|
getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
|
||||||
|
|
||||||
// Transform the clauses
|
// Transform the clauses
|
||||||
SmallVector<OMPClause *, 5> TClauses;
|
llvm::SmallVector<OMPClause *, 16> TClauses;
|
||||||
ArrayRef<OMPClause *> Clauses = D->clauses();
|
ArrayRef<OMPClause *> Clauses = D->clauses();
|
||||||
TClauses.reserve(Clauses.size());
|
TClauses.reserve(Clauses.size());
|
||||||
for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
|
for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
if (*I) {
|
if (*I) {
|
||||||
OMPClause *Clause = getDerived().TransformOMPClause(*I);
|
OMPClause *Clause = getDerived().TransformOMPClause(*I);
|
||||||
if (!Clause)
|
if (!Clause) {
|
||||||
|
getSema().EndOpenMPDSABlock(0);
|
||||||
return StmtError();
|
return StmtError();
|
||||||
|
}
|
||||||
TClauses.push_back(Clause);
|
TClauses.push_back(Clause);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TClauses.push_back(0);
|
TClauses.push_back(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!D->getAssociatedStmt())
|
if (!D->getAssociatedStmt()) {
|
||||||
|
getSema().EndOpenMPDSABlock(0);
|
||||||
return StmtError();
|
return StmtError();
|
||||||
|
}
|
||||||
StmtResult AssociatedStmt =
|
StmtResult AssociatedStmt =
|
||||||
getDerived().TransformStmt(D->getAssociatedStmt());
|
getDerived().TransformStmt(D->getAssociatedStmt());
|
||||||
if (AssociatedStmt.isInvalid())
|
if (AssociatedStmt.isInvalid()) {
|
||||||
|
getSema().EndOpenMPDSABlock(0);
|
||||||
return StmtError();
|
return StmtError();
|
||||||
|
}
|
||||||
|
|
||||||
return getDerived().RebuildOMPParallelDirective(TClauses,
|
StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
|
||||||
AssociatedStmt.take(),
|
AssociatedStmt.take(),
|
||||||
D->getLocStart(),
|
D->getLocStart(),
|
||||||
D->getLocEnd());
|
D->getLocEnd());
|
||||||
|
getSema().EndOpenMPDSABlock(Res.get());
|
||||||
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
|
@ -6296,7 +6315,7 @@ TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
OMPClause *
|
OMPClause *
|
||||||
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
|
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
SmallVector<Expr *, 5> Vars;
|
llvm::SmallVector<Expr *, 16> Vars;
|
||||||
Vars.reserve(C->varlist_size());
|
Vars.reserve(C->varlist_size());
|
||||||
for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
|
for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
|
||||||
E = C->varlist_end();
|
E = C->varlist_end();
|
||||||
|
@ -6312,6 +6331,25 @@ TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
C->getLocEnd());
|
C->getLocEnd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Derived>
|
||||||
|
OMPClause *
|
||||||
|
TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
|
||||||
|
llvm::SmallVector<Expr *, 16> Vars;
|
||||||
|
Vars.reserve(C->varlist_size());
|
||||||
|
for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),
|
||||||
|
E = C->varlist_end();
|
||||||
|
I != E; ++I) {
|
||||||
|
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
|
||||||
|
if (EVar.isInvalid())
|
||||||
|
return 0;
|
||||||
|
Vars.push_back(EVar.take());
|
||||||
|
}
|
||||||
|
return getDerived().RebuildOMPSharedClause(Vars,
|
||||||
|
C->getLocStart(),
|
||||||
|
C->getLParenLoc(),
|
||||||
|
C->getLocEnd());
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Expression transformation
|
// Expression transformation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -1689,6 +1689,9 @@ OMPClause *OMPClauseReader::readClause() {
|
||||||
case OMPC_private:
|
case OMPC_private:
|
||||||
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
|
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
|
||||||
break;
|
break;
|
||||||
|
case OMPC_shared:
|
||||||
|
C = OMPSharedClause::CreateEmpty(Context, Record[Idx++]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Visit(C);
|
Visit(C);
|
||||||
C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
|
C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
|
||||||
|
@ -1714,6 +1717,16 @@ void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
C->setVarRefs(Vars);
|
C->setVarRefs(Vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) {
|
||||||
|
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
|
||||||
|
unsigned NumVars = C->varlist_size();
|
||||||
|
SmallVector<Expr *, 16> Vars;
|
||||||
|
Vars.reserve(NumVars);
|
||||||
|
for (unsigned i = 0; i != NumVars; ++i)
|
||||||
|
Vars.push_back(Reader->Reader.ReadSubExpr());
|
||||||
|
C->setVarRefs(Vars);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// OpenMP Directives.
|
// OpenMP Directives.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -1703,6 +1703,15 @@ void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
Writer->Writer.AddStmt(*I);
|
Writer->Writer.AddStmt(*I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) {
|
||||||
|
Record.push_back(C->varlist_size());
|
||||||
|
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
|
||||||
|
for (OMPVarList<OMPSharedClause>::varlist_iterator I = C->varlist_begin(),
|
||||||
|
E = C->varlist_end();
|
||||||
|
I != E; ++I)
|
||||||
|
Writer->Writer.AddStmt(*I);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// OpenMP Directives.
|
// OpenMP Directives.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 -o - %s
|
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s
|
||||||
|
|
||||||
#pragma omp // expected-error {{expected an OpenMP directive}}
|
#pragma omp // expected-error {{expected an OpenMP directive}}
|
||||||
#pragma omp unknown_directive // expected-error {{expected an OpenMP directive}}
|
#pragma omp unknown_directive // expected-error {{expected an OpenMP directive}}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 -o - %s
|
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s
|
||||||
|
|
||||||
void foo();
|
void foo();
|
||||||
|
|
||||||
|
@ -11,5 +11,11 @@ int main(int argc, char **argv) {
|
||||||
#pragma omp parallel default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
|
#pragma omp parallel default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}}
|
||||||
foo();
|
foo();
|
||||||
|
|
||||||
|
#pragma omp parallel default(none)
|
||||||
|
++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
|
||||||
|
|
||||||
|
#pragma omp parallel default(none)
|
||||||
|
#pragma omp parallel default(shared)
|
||||||
|
++argc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma omp parallel // expected-error {{unexpected OpenMP directive '#pragma omp parallel'}}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
#pragma omp parallel
|
||||||
|
#pragma omp parallel unknown() // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
|
||||||
|
foo();
|
||||||
|
L1:
|
||||||
|
foo();
|
||||||
|
#pragma omp parallel
|
||||||
|
;
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
goto L1; // expected-error {{use of undeclared label 'L1'}}
|
||||||
|
argc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
switch(argc) {
|
||||||
|
case (0):
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
foo();
|
||||||
|
break; // expected-error {{'break' statement not in loop or switch statement}}
|
||||||
|
continue; // expected-error {{'continue' statement not in loop statement}}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma omp parallel default(none)
|
||||||
|
++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
|
||||||
|
|
||||||
|
goto L2; // expected-error {{use of undeclared label 'L2'}}
|
||||||
|
#pragma omp parallel
|
||||||
|
L2:
|
||||||
|
foo();
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
return 1; // expected-error {{cannot return from OpenMP region}}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 %s
|
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class S2 {
|
||||||
mutable int a;
|
mutable int a;
|
||||||
public:
|
public:
|
||||||
S2():a(0) { }
|
S2():a(0) { }
|
||||||
static float S2s;
|
static float S2s; // expected-note {{predetermined as shared}}
|
||||||
};
|
};
|
||||||
const S2 b;
|
const S2 b;
|
||||||
const S2 ba[5];
|
const S2 ba[5];
|
||||||
|
@ -22,9 +22,9 @@ class S3 {
|
||||||
public:
|
public:
|
||||||
S3():a(0) { }
|
S3():a(0) { }
|
||||||
};
|
};
|
||||||
const S3 c;
|
const S3 c; // expected-note {{predetermined as shared}}
|
||||||
const S3 ca[5];
|
const S3 ca[5]; // expected-note {{predetermined as shared}}
|
||||||
extern const int f;
|
extern const int f; // expected-note {{predetermined as shared}}
|
||||||
class S4 { // expected-note {{'S4' declared here}}
|
class S4 { // expected-note {{'S4' declared here}}
|
||||||
int a;
|
int a;
|
||||||
S4();
|
S4();
|
||||||
|
@ -38,9 +38,12 @@ public:
|
||||||
S5(int v):a(v) { }
|
S5(int v):a(v) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int threadvar;
|
||||||
|
#pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
const int d = 5;
|
const int d = 5; // expected-note {{predetermined as shared}}
|
||||||
const int da[5] = { 0 };
|
const int da[5] = { 0 }; // expected-note {{predetermined as shared}}
|
||||||
S4 e(4); // expected-note {{'e' defined here}}
|
S4 e(4); // expected-note {{'e' defined here}}
|
||||||
S5 g(5); // expected-note {{'g' defined here}}
|
S5 g(5); // expected-note {{'g' defined here}}
|
||||||
int i;
|
int i;
|
||||||
|
@ -53,13 +56,14 @@ int main(int argc, char **argv) {
|
||||||
#pragma omp parallel private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
|
#pragma omp parallel private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
|
||||||
#pragma omp parallel private (argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}
|
#pragma omp parallel private (argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}
|
||||||
#pragma omp parallel private (S1) // expected-error {{'S1' does not refer to a value}}
|
#pragma omp parallel private (S1) // expected-error {{'S1' does not refer to a value}}
|
||||||
#pragma omp parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}}
|
#pragma omp parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}}
|
||||||
#pragma omp parallel private (argv[1]) // expected-error {{expected variable name}}
|
#pragma omp parallel private (argv[1]) // expected-error {{expected variable name}}
|
||||||
#pragma omp parallel private(ba)
|
#pragma omp parallel private(ba)
|
||||||
#pragma omp parallel private(ca)
|
#pragma omp parallel private(ca) // expected-error {{shared variable cannot be private}}
|
||||||
#pragma omp parallel private(da)
|
#pragma omp parallel private(da) // expected-error {{shared variable cannot be private}}
|
||||||
#pragma omp parallel private(S2::S2s)
|
#pragma omp parallel private(S2::S2s) // expected-error {{shared variable cannot be private}}
|
||||||
#pragma omp parallel private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}
|
#pragma omp parallel private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}}
|
||||||
|
#pragma omp parallel private(threadvar) // expected-error {{threadprivate or thread local variable cannot be private}}
|
||||||
foo();
|
foo();
|
||||||
#pragma omp parallel private(i)
|
#pragma omp parallel private(i)
|
||||||
#pragma omp parallel private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type 'int &'}}
|
#pragma omp parallel private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type 'int &'}}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool foobool(int argc) {
|
||||||
|
return argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S1; // expected-note {{declared here}}
|
||||||
|
extern S1 a;
|
||||||
|
class S2 {
|
||||||
|
mutable int a;
|
||||||
|
public:
|
||||||
|
S2():a(0) { }
|
||||||
|
S2(S2 &s2):a(s2.a) { }
|
||||||
|
};
|
||||||
|
const S2 b;
|
||||||
|
const S2 ba[5];
|
||||||
|
class S3 {
|
||||||
|
int a;
|
||||||
|
public:
|
||||||
|
S3():a(0) { }
|
||||||
|
S3(S3 &s3):a(s3.a) { }
|
||||||
|
};
|
||||||
|
const S3 c;
|
||||||
|
const S3 ca[5];
|
||||||
|
extern const int f;
|
||||||
|
class S4 {
|
||||||
|
int a;
|
||||||
|
S4();
|
||||||
|
S4(const S4 &s4);
|
||||||
|
public:
|
||||||
|
S4(int v):a(v) { }
|
||||||
|
};
|
||||||
|
class S5 {
|
||||||
|
int a;
|
||||||
|
S5():a(0) {}
|
||||||
|
S5(const S5 &s5):a(s5.a) { }
|
||||||
|
public:
|
||||||
|
S5(int v):a(v) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
S3 h;
|
||||||
|
#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
const int d = 5;
|
||||||
|
const int da[5] = { 0 };
|
||||||
|
S4 e(4);
|
||||||
|
S5 g(5);
|
||||||
|
int i;
|
||||||
|
int &j = i;
|
||||||
|
#pragma omp parallel shared // expected-error {{expected '(' after 'shared'}}
|
||||||
|
#pragma omp parallel shared ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
|
||||||
|
#pragma omp parallel shared () // expected-error {{expected expression}}
|
||||||
|
#pragma omp parallel shared (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
|
||||||
|
#pragma omp parallel shared (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
|
||||||
|
#pragma omp parallel shared (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
|
||||||
|
#pragma omp parallel shared (argc)
|
||||||
|
#pragma omp parallel shared (S1) // expected-error {{'S1' does not refer to a value}}
|
||||||
|
#pragma omp parallel shared (a, b, c, d, f)
|
||||||
|
#pragma omp parallel shared (argv[1]) // expected-error {{expected variable name}}
|
||||||
|
#pragma omp parallel shared(ba)
|
||||||
|
#pragma omp parallel shared(ca)
|
||||||
|
#pragma omp parallel shared(da)
|
||||||
|
#pragma omp parallel shared(e, g)
|
||||||
|
#pragma omp parallel shared(h) // expected-error {{threadprivate or thread local variable cannot be shared}}
|
||||||
|
#pragma omp parallel private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}}
|
||||||
|
foo();
|
||||||
|
#pragma omp parallel private(i)
|
||||||
|
#pragma omp parallel shared(i)
|
||||||
|
#pragma omp parallel shared(j)
|
||||||
|
foo();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1936,6 +1936,9 @@ void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
|
||||||
void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
|
void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
|
||||||
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
PROCESS_OMP_CLAUSE_LIST(OMPPrivateClause, C)
|
||||||
}
|
}
|
||||||
|
void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) {
|
||||||
|
PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)
|
||||||
|
}
|
||||||
#undef PROCESS_OMP_CLAUSE_LIST
|
#undef PROCESS_OMP_CLAUSE_LIST
|
||||||
}
|
}
|
||||||
void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {
|
void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {
|
||||||
|
|
|
@ -2337,6 +2337,12 @@ bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Derived>
|
||||||
|
bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
|
||||||
|
PROCESS_OMP_CLAUSE_LIST(OMPSharedClause, C)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#undef PROCESS_OMP_CLAUSE_LIST
|
#undef PROCESS_OMP_CLAUSE_LIST
|
||||||
|
|
||||||
// FIXME: look at the following tricky-seeming exprs to see if we
|
// FIXME: look at the following tricky-seeming exprs to see if we
|
||||||
|
|
Loading…
Reference in New Issue