r200513 - [OPENMP] Bug fixes in threadprivate declaration and data sharing attributes processing. (http://llvm-reviews.chandlerc.com/D2451)
Alexey Bataev
a.bataev at hotmail.com
Thu Jan 30 21:15:34 PST 2014
Author: abataev
Date: Thu Jan 30 23:15:34 2014
New Revision: 200513
URL: http://llvm.org/viewvc/llvm-project?rev=200513&view=rev
Log:
[OPENMP] Bug fixes in threadprivate declaration and data sharing attributes processing. (http://llvm-reviews.chandlerc.com/D2451)
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=200513&r1=200512&r2=200513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Jan 30 23:15:34 2014
@@ -82,6 +82,9 @@ private:
typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator;
DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D);
+
+ /// \brief Checks if the variable is a local for OpenMP region.
+ bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter);
public:
explicit DSAStackTy(Sema &S) : Stack(1), Actions(S) { }
@@ -98,9 +101,6 @@ public:
/// \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);
@@ -152,7 +152,21 @@ DSAStackTy::DSAVarData DSAStackTy::getDS
return DVar;
}
+
DVar.DKind = Iter->Directive;
+ // 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 (DVar.DKind != OMPD_parallel) {
+ if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() &&
+ (D->getStorageClass() == SC_Auto ||
+ D->getStorageClass() == SC_None)) {
+ DVar.CKind = OMPC_private;
+ return DVar;
+ }
+ }
+
// Explicitly specified attributes and local variables with predetermined
// attributes.
if (Iter->SharingMap.count(D)) {
@@ -189,8 +203,8 @@ DSAStackTy::DSAVarData DSAStackTy::getDS
// TODO
if (DVar.DKind == OMPD_task) {
DSAVarData DVarTemp;
- for (StackTy::reverse_iterator I = Iter + 1,
- EE = Stack.rend() - 1;
+ for (StackTy::reverse_iterator I = llvm::next(Iter),
+ EE = llvm::prior(Stack.rend());
I != EE; ++I) {
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
// in a Construct, implicitly determined, p.6]
@@ -217,7 +231,7 @@ DSAStackTy::DSAVarData DSAStackTy::getDS
// 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);
+ return getDSA(llvm::next(Iter), D);
}
void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {
@@ -231,23 +245,23 @@ void DSAStackTy::addDSA(VarDecl *D, Decl
}
}
-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())
+bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) {
+ if (Stack.size() > 2) {
+ reverse_iterator I = Iter, E = Stack.rend() - 1;
+ Scope *TopScope = 0;
+ while (I != E &&
+ I->Directive != OMPD_parallel) {
+ ++I;
+ }
+ if (I == E) return false;
+ TopScope = I->CurScope ? I->CurScope->getParent() : 0;
+ Scope *CurScope = getCurScope();
+ while (CurScope != TopScope && !CurScope->isDeclScope(D)) {
CurScope = CurScope->getParent();
- isOpenMPLocal =
- CurScope &&
- isa<CapturedDecl>(D->getDeclContext()) &&
- CurScope->getFnParent()->getEntity()->Encloses(D->getDeclContext());
+ }
+ return CurScope != TopScope;
}
- return isOpenMPLocal;
+ return false;
}
DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) {
@@ -270,11 +284,13 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
// 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;
+ OpenMPDirectiveKind Kind = getCurrentDirective();
+ if (Kind != OMPD_parallel) {
+ if (isOpenMPLocal(D, llvm::next(Stack.rbegin())) && 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
@@ -319,7 +335,7 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
// 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()) {
+ if (D->isStaticLocal()) {
DVar.CKind = OMPC_shared;
return DVar;
}
@@ -335,13 +351,13 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
}
DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) {
- return getDSA(Stack.rbegin() + 1, D);
+ return getDSA(llvm::next(Stack.rbegin()), D);
}
DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, OpenMPClauseKind CKind,
OpenMPDirectiveKind DKind) {
- for (StackTy::reverse_iterator I = Stack.rbegin() + 1,
- E = Stack.rend() - 1;
+ for (StackTy::reverse_iterator I = llvm::next(Stack.rbegin()),
+ E = llvm::prior(Stack.rend());
I != E; ++I) {
if (DKind != OMPD_unknown && DKind != I->Directive) continue;
DSAVarData DVar = getDSA(I, D);
@@ -567,10 +583,13 @@ OMPThreadPrivateDecl *Sema::CheckOMPThre
Vars.push_back(*I);
}
- return Vars.empty() ?
- 0 : OMPThreadPrivateDecl::Create(Context,
- getCurLexicalContext(),
- Loc, Vars);
+ OMPThreadPrivateDecl *D = 0;
+ if (!Vars.empty()) {
+ D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc,
+ Vars);
+ D->setAccess(AS_public);
+ }
+ return D;
}
namespace {
Modified: cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp?rev=200513&r1=200512&r2=200513&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp Thu Jan 30 23:15:34 2014
@@ -2,8 +2,6 @@
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print
// expected-no-diagnostics
-// FIXME: This test has been crashing since r186647.
-// REQUIRES: disabled
#ifndef HEADER
#define HEADER
More information about the cfe-commits
mailing list