Skip to content

Commit dec740d

Browse files
committed
Restrict user's DSAs in struct/class member functions. Only allow static storage without using 'this'
struct S { static int x; void f() { #pragma oss task firstprivate(x, S::x) {} } }; Closes llvm#40
1 parent 4de58d3 commit dec740d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/Sema/SemaOmpSs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,17 +853,20 @@ getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc,
853853
auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr);
854854
auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr);
855855

856+
// Only allow VarDecl from DeclRefExpr
857+
// and VarDecl implicits from MemberExpr // (i.e. static members without 'this')
856858
if ((!DE || !isa<VarDecl>(DE->getDecl())) &&
857859
(S.getCurrentThisType().isNull() || !ME ||
858860
!isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) ||
859-
!isa<FieldDecl>(ME->getMemberDecl()))) {
861+
!cast<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())->isImplicit() ||
862+
!isa<VarDecl>(ME->getMemberDecl()))) {
860863

861864
S.Diag(ELoc, diag::err_oss_expected_var_name_member_expr)
862865
<< (S.getCurrentThisType().isNull() ? 0 : 1) << ERange;
863866
return nullptr;
864867
}
865868

866-
auto *VD = dyn_cast<VarDecl>(DE->getDecl());
869+
auto *VD = cast<VarDecl>(DE ? DE->getDecl() : ME->getMemberDecl());
867870
QualType Type = VD->getType();
868871
if (!Type.isPODType(S.Context)) {
869872
S.Diag(ELoc, diag::err_oss_non_pod_not_supported) << ERange;

clang/test/OmpSs/Sema/task_dsa.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// RUN: %clang_cc1 -x c++ -verify -fompss-2 -ferror-limit 100 %s
22

33
struct S {
4-
int x;
4+
static int x;
5+
int y;
56
void f() {
6-
#pragma oss task shared(this) // expected-error {{expected variable name or data member of current class}}
7-
{}
7+
#pragma oss task shared(this, *this, y, this->y, this->x) // expected-error {{expected variable name or data member of current class}} expected-error {{expected variable name or data member of current class}} expected-error {{expected variable name or data member of current class}} expected-error {{expected variable name or data member of current class}} expected-error {{expected variable name or data member of current class}}
8+
{ /* ERROR */ }
9+
#pragma oss task shared(x, S::x)
10+
{ /* FINE */ }
811
}
912
};
1013

0 commit comments

Comments
 (0)