Skip to content

Commit 98456c3

Browse files
committed
[OPENMP] Fix DSA processing for member declaration.
If the member declaration is captured in the OMPCapturedExprDecl, we may loose data-sharing attribute info for this declaration. Patch fixes this bug. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308629 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7de981a commit 98456c3

File tree

54 files changed

+147
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+147
-139
lines changed

lib/Sema/SemaExprMember.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1848,8 +1848,10 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
18481848
if (getLangOpts().OpenMP && IsArrow &&
18491849
!CurContext->isDependentContext() &&
18501850
isa<CXXThisExpr>(Base.get()->IgnoreParenImpCasts())) {
1851-
if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field))
1852-
return getOpenMPCapturedExpr(PrivateCopy, VK, OK, OpLoc);
1851+
if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field)) {
1852+
return getOpenMPCapturedExpr(PrivateCopy, VK, OK,
1853+
MemberNameInfo.getLoc());
1854+
}
18531855
}
18541856

18551857
return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,

lib/Sema/SemaOpenMP.cpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DSAStackTy final {
5555
Expr *RefExpr = nullptr;
5656
DeclRefExpr *PrivateCopy = nullptr;
5757
SourceLocation ImplicitDSALoc;
58-
DSAVarData() {}
58+
DSAVarData() = default;
5959
};
6060
typedef llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4>
6161
OperatorOffsetTy;
@@ -112,7 +112,7 @@ class DSAStackTy final {
112112
Scope *CurScope, SourceLocation Loc)
113113
: Directive(DKind), DirectiveName(Name), CurScope(CurScope),
114114
ConstructLoc(Loc) {}
115-
SharingMapTy() {}
115+
SharingMapTy() = default;
116116
};
117117

118118
typedef SmallVector<SharingMapTy, 4> StackTy;
@@ -479,7 +479,25 @@ bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) {
479479
}
480480
} // namespace
481481

482+
static Expr *getExprAsWritten(Expr *E) {
483+
if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E))
484+
E = ExprTemp->getSubExpr();
485+
486+
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
487+
E = MTE->GetTemporaryExpr();
488+
489+
while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
490+
E = Binder->getSubExpr();
491+
492+
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
493+
E = ICE->getSubExprAsWritten();
494+
return E->IgnoreParens();
495+
}
496+
482497
static ValueDecl *getCanonicalDecl(ValueDecl *D) {
498+
if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D))
499+
if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
500+
D = ME->getMemberDecl();
483501
auto *VD = dyn_cast<VarDecl>(D);
484502
auto *FD = dyn_cast<FieldDecl>(D);
485503
if (VD != nullptr) {
@@ -821,6 +839,7 @@ DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) {
821839
DVar.PrivateCopy = I->SharingMap[D].PrivateCopy;
822840
DVar.CKind = I->SharingMap[D].Attributes;
823841
DVar.ImplicitDSALoc = I->DefaultAttrLoc;
842+
DVar.DKind = I->Directive;
824843
}
825844

826845
return DVar;
@@ -3053,21 +3072,6 @@ bool OpenMPIterationSpaceChecker::Dependent() const {
30533072
(Step && Step->isValueDependent());
30543073
}
30553074

3056-
static Expr *getExprAsWritten(Expr *E) {
3057-
if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E))
3058-
E = ExprTemp->getSubExpr();
3059-
3060-
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
3061-
E = MTE->GetTemporaryExpr();
3062-
3063-
while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
3064-
E = Binder->getSubExpr();
3065-
3066-
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
3067-
E = ICE->getSubExprAsWritten();
3068-
return E->IgnoreParens();
3069-
}
3070-
30713075
bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl,
30723076
Expr *NewLCRefExpr,
30733077
Expr *NewLB) {
@@ -3249,12 +3253,8 @@ static const ValueDecl *GetInitLCDecl(Expr *E) {
32493253
CE->getNumArgs() > 0 && CE->getArg(0) != nullptr)
32503254
E = CE->getArg(0)->IgnoreParenImpCasts();
32513255
if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) {
3252-
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
3253-
if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD))
3254-
if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit())))
3255-
return getCanonicalDecl(ME->getMemberDecl());
3256+
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
32563257
return getCanonicalDecl(VD);
3257-
}
32583258
}
32593259
if (auto *ME = dyn_cast_or_null<MemberExpr>(E))
32603260
if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()))
@@ -8097,7 +8097,8 @@ getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc,
80978097
}
80988098
return std::make_pair(nullptr, false);
80998099
}
8100-
return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false);
8100+
return std::make_pair(
8101+
getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false);
81018102
}
81028103

81038104
OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
@@ -8981,7 +8982,6 @@ static bool ActOnOMPReductionKindClause(
89818982
// C++
89828983
// reduction-identifier is either an id-expression or one of the following
89838984
// operators: +, -, *, &, |, ^, && and ||
8984-
// FIXME: Only 'min' and 'max' identifiers are supported for now.
89858985
switch (OOK) {
89868986
case OO_Plus:
89878987
case OO_Minus:
@@ -9044,7 +9044,7 @@ static bool ActOnOMPReductionKindClause(
90449044
case NUM_OVERLOADED_OPERATORS:
90459045
llvm_unreachable("Unexpected reduction identifier");
90469046
case OO_None:
9047-
if (auto II = DN.getAsIdentifierInfo()) {
9047+
if (auto *II = DN.getAsIdentifierInfo()) {
90489048
if (II->isStr("max"))
90499049
BOK = BO_GT;
90509050
else if (II->isStr("min"))
@@ -9055,6 +9055,8 @@ static bool ActOnOMPReductionKindClause(
90559055
SourceRange ReductionIdRange;
90569056
if (ReductionIdScopeSpec.isValid())
90579057
ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc());
9058+
else
9059+
ReductionIdRange.setBegin(ReductionId.getBeginLoc());
90589060
ReductionIdRange.setEnd(ReductionId.getEndLoc());
90599061

90609062
auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end();
@@ -9166,6 +9168,7 @@ static bool ActOnOMPReductionKindClause(
91669168
<< getOpenMPClauseName(ClauseKind);
91679169
if (DVar.RefExpr)
91689170
S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced);
9171+
continue;
91699172
} else if (DVar.CKind != OMPC_unknown) {
91709173
S.Diag(ELoc, diag::err_omp_wrong_dsa)
91719174
<< getOpenMPClauseName(DVar.CKind)
@@ -9453,9 +9456,10 @@ static bool ActOnOMPReductionKindClause(
94539456
S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(),
94549457
BO_Assign, LHSDRE, ConditionalOp);
94559458
}
9456-
ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get());
9459+
if (ReductionOp.isUsable())
9460+
ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get());
94579461
}
9458-
if (ReductionOp.isInvalid())
9462+
if (!ReductionOp.isUsable())
94599463
continue;
94609464
}
94619465

@@ -9767,10 +9771,6 @@ static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV,
97679771
HasErrors = true;
97689772
continue;
97699773
}
9770-
if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) {
9771-
D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts())
9772-
->getMemberDecl();
9773-
}
97749774
auto &&Info = Stack->isLoopControlVariable(D);
97759775
Expr *InitExpr = *CurInit;
97769776

test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
const S2 &operator =(const S2&) const;
1919
S2 &operator =(const S2&);
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/distribute_parallel_for_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class S2 {
2727
S2() : a(0) {}
2828
S2(S2 &s2) : a(s2.a) {}
2929
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
30-
static const float S2sc;
30+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
3131
};
32-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
32+
const float S2::S2sc = 0;
3333
S2 b; // expected-note 3 {{'b' defined here}}
3434
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3535
class S3 {

test/OpenMP/distribute_parallel_for_simd_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
const S2 &operator =(const S2&) const;
1919
S2 &operator =(const S2&);
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class S2 {
2727
S2() : a(0) {}
2828
S2(S2 &s2) : a(s2.a) {}
2929
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
30-
static const float S2sc;
30+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
3131
};
32-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
32+
const float S2::S2sc = 0;
3333
S2 b; // expected-note 3 {{'b' defined here}}
3434
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3535
class S3 {

test/OpenMP/distribute_simd_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
const S2 &operator =(const S2&) const;
1919
S2 &operator =(const S2&);
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/distribute_simd_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class S2 {
2727
S2() : a(0) {}
2828
S2(S2 &s2) : a(s2.a) {}
2929
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
30-
static const float S2sc;
30+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
3131
};
32-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
32+
const float S2::S2sc = 0;
3333
S2 b; // expected-note 3 {{'b' defined here}}
3434
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3535
class S3 {

test/OpenMP/dump.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ struct S {
5252
// CHECK-NEXT: | |-OMPScheduleClause {{.+}} <col:61, col:79>
5353
// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} <col:78> 'int' <LValueToRValue>
5454
// CHECK-NEXT: | | `-DeclRefExpr {{.+}} <col:78> 'int' lvalue OMPCapturedExpr {{.+}} '.capture_expr.' 'int'
55-
// CHECK-NEXT: | |-CapturedStmt {{.+}} <line:40:5, <invalid sloc>>
55+
// CHECK-NEXT: | |-CapturedStmt {{.+}} <line:40:5, line:41:9>
5656
// CHECK-NEXT: | | |-CapturedDecl {{.+}} <<invalid sloc>> <invalid sloc>
57-
// CHECK-NEXT: | | | |-ForStmt {{.+}} <col:5, <invalid sloc>>
58-
// CHECK: | | | | `-UnaryOperator {{.+}} <line:41:7, <invalid sloc>> 'int' lvalue prefix '++'
59-
// CHECK-NEXT: | | | | `-DeclRefExpr {{.+}} <<invalid sloc>> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &'
57+
// CHECK-NEXT: | | | |-ForStmt {{.+}} <line:40:5, line:41:9>
58+
// CHECK: | | | | `-UnaryOperator {{.+}} <line:41:7, col:9> 'int' lvalue prefix '++'
59+
// CHECK-NEXT: | | | | `-DeclRefExpr {{.+}} <col:9> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &'
6060

6161
#pragma omp declare simd
6262
#pragma omp declare simd inbranch

test/OpenMP/for_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
const S2 &operator =(const S2&) const;
1919
S2 &operator =(const S2&);
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/for_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class S2 {
2626
S2() : a(0) {}
2727
S2(S2 &s2) : a(s2.a) {}
2828
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
29-
static const float S2sc;
29+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
3030
};
31-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
31+
const float S2::S2sc = 0;
3232
S2 b; // expected-note 3 {{'b' defined here}}
3333
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3434
class S3 {

test/OpenMP/for_simd_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
S2 &operator =(const S2&);
1919
const S2 &operator =(const S2&) const;
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/for_simd_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class S2 {
2626
S2() : a(0) {}
2727
S2(S2 &s2) : a(s2.a) {}
2828
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
29-
static const float S2sc;
29+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
3030
};
31-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
31+
const float S2::S2sc = 0;
3232
S2 b; // expected-note 3 {{'b' defined here}}
3333
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3434
class S3 {

test/OpenMP/parallel_for_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class S2 {
1818
S2 &operator=(const S2 &);
1919
const S2 &operator=(const S2 &) const;
2020
static float S2s; // expected-note {{static data member is predetermined as shared}}
21-
static const float S2sc;
21+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2222
};
23-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23+
const float S2::S2sc = 0;
2424
const S2 b;
2525
const S2 ba[5];
2626
class S3 {

test/OpenMP/parallel_for_reduction_messages.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class S2 {
2525
S2() : a(0) {}
2626
S2(S2 &s2) : a(s2.a) {}
2727
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
28-
static const float S2sc;
28+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
2929
};
30-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
30+
const float S2::S2sc = 0;
3131
S2 b; // expected-note 3 {{'b' defined here}}
3232
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3333
class S3 {
@@ -61,6 +61,12 @@ class S5 {
6161

6262
public:
6363
S5(int v) : a(v) {}
64+
void foo() {
65+
#pragma omp parallel private(a) // expected-note {{defined as private}}
66+
#pragma omp for reduction(+:a) // expected-error {{reduction variable must be shared}}
67+
for (int i = 0; i < 10; ++i)
68+
::foo();
69+
}
6470
};
6571
class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
6672
#if __cplusplus >= 201103L // C++11 or later

test/OpenMP/parallel_for_simd_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class S2 {
1717
S2(S2 &s2) : a(s2.a) {}
1818
const S2 &operator=(const S2 &) const;
1919
static float S2s; // expected-note {{static data member is predetermined as shared}}
20-
static const float S2sc;
20+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2121
};
22-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
22+
const float S2::S2sc = 0;
2323
const S2 b;
2424
const S2 ba[5];
2525
class S3 {

test/OpenMP/parallel_for_simd_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class S2 {
2525
S2() : a(0) {}
2626
S2(S2 &s2) : a(s2.a) {}
2727
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
28-
static const float S2sc;
28+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
2929
};
30-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
30+
const float S2::S2sc = 0;
3131
S2 b; // expected-note 3 {{'b' defined here}}
3232
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3333
class S3 {

test/OpenMP/parallel_reduction_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class S2 {
2424
S2() : a(0) {}
2525
S2(S2 &s2) : a(s2.a) {}
2626
static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
27-
static const float S2sc;
27+
static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
2828
};
29-
const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
29+
const float S2::S2sc = 0;
3030
S2 b; // expected-note 3 {{'b' defined here}}
3131
const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
3232
class S3 {

test/OpenMP/parallel_sections_lastprivate_messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class S2 {
1717
S2(S2 &s2) : a(s2.a) {}
1818
const S2 &operator=(const S2 &) const;
1919
static float S2s; // expected-note {{static data member is predetermined as shared}}
20-
static const float S2sc;
20+
static const float S2sc; // expected-note {{static data member is predetermined as shared}}
2121
};
22-
const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
22+
const float S2::S2sc = 0;
2323
const S2 b;
2424
const S2 ba[5];
2525
class S3 {

0 commit comments

Comments
 (0)