Skip to content

Commit a4c01b0

Browse files
committed
Perform lvalue-to-rvalue conversion in shape expressions
Closes llvm#64
1 parent 4e81c90 commit a4c01b0

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10869,7 +10869,6 @@ def err_oss_wrong_dsa : Error<
1086910869
"%0 variable cannot be %1">;
1087010870
def err_oss_array_section_use : Error<"OmpSs-2 array section is not allowed here">;
1087110871
def err_oss_array_shaping_use : Error<"OmpSs-2 array shaping is not allowed here">;
10872-
def err_oss_array_shaping_use_section : Error<"OmpSs-2 array section is not allowed in array shaping">;
1087310872
def err_oss_mismatch_depend_dsa : Error<
1087410873
"the data-sharing '%0' conflicts with '%1' required by the dependency">;
1087510874
def err_oss_not_defined_dsa_when_default_none : Error<

clang/lib/Sema/SemaExpr.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5160,10 +5160,12 @@ ExprResult Sema::ActOnOSSArrayShapingExpr(Expr *Base, ArrayRef<Expr *> Shapes,
51605160

51615161
if (!Base) {
51625162
ErrorFound = true;
5163-
} else if (auto *OASE = dyn_cast<OSSArraySectionExpr>(Base->IgnoreParens())) {
5164-
Diag(OASE->getBeginLoc(), diag::err_oss_array_shaping_use_section)
5165-
<< OASE->getSourceRange();
5166-
ErrorFound = true;
5163+
} else {
5164+
ExprResult Result = CheckPlaceholderExpr(Base);
5165+
if (Result.isInvalid()) {
5166+
Base = Result.get();
5167+
ErrorFound = true;
5168+
}
51675169
}
51685170

51695171
for (Expr *const &E : Shapes) {
@@ -5220,20 +5222,31 @@ ExprResult Sema::ActOnOSSArrayShapingExpr(Expr *Base, ArrayRef<Expr *> Shapes,
52205222
ErrorFound = true;
52215223
}
52225224

5225+
SmallVector<Expr *, 4> NewShapes;
52235226
for (int i = Shapes.size() - 1 ; i >= 0; --i) {
5224-
auto Res = PerformOmpSsImplicitIntegerConversion(Shapes[i]->getExprLoc(),
5225-
Shapes[i]);
5227+
Expr *NewShape = Shapes[i];
5228+
ExprResult Result = DefaultLvalueConversion(NewShape);
5229+
if (Result.isInvalid()) {
5230+
ErrorFound = true;
5231+
continue;
5232+
}
5233+
NewShape = Result.get();
5234+
5235+
auto Res = PerformOmpSsImplicitIntegerConversion(NewShape->getExprLoc(),
5236+
NewShape);
52265237
if (Res.isInvalid()) {
52275238
ErrorFound = true;
52285239
// FIXME: PerformContextualImplicitConversion doesn't always tell us if it
52295240
// failed and produced a diagnostic.
52305241
// From commit ef6c43dc
5231-
Diag(Shapes[i]->getExprLoc(), diag::err_oss_typecheck_shape_not_integer)
5232-
<< 0 << Shapes[i]->getSourceRange();
5242+
Diag(NewShape->getExprLoc(), diag::err_oss_typecheck_shape_not_integer)
5243+
<< 0 << NewShape->getSourceRange();
52335244
continue;
52345245
}
5246+
NewShape = Res.get();
5247+
NewShapes.insert(NewShapes.begin(), NewShape);
52355248

5236-
Type = BuildArrayType(Type, ArrayType::Normal, Res.get(), /*Quals=*/0,
5249+
Type = BuildArrayType(Type, ArrayType::Normal, NewShape, /*Quals=*/0,
52375250
Shapes[i]->getSourceRange(),
52385251
DeclarationName());
52395252
if (Type.isNull())
@@ -5251,7 +5264,7 @@ ExprResult Sema::ActOnOSSArrayShapingExpr(Expr *Base, ArrayRef<Expr *> Shapes,
52515264
return ExprError();
52525265

52535266
return OSSArrayShapingExpr::Create(Context, Type,
5254-
VK_LValue, OK_Ordinary, Base, Shapes, LBLoc, RBLoc);
5267+
VK_LValue, OK_Ordinary, Base, NewShapes, LBLoc, RBLoc);
52555268
}
52565269

52575270
ExprResult Sema::ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -verify -fompss-2 -ast-dump -ferror-limit 100 %s | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
struct S {
5+
static constexpr int N = 4;
6+
};
7+
8+
void foo(int *p) {
9+
#pragma oss task in([S::N]p)
10+
{}
11+
}
12+
13+
// CHECK: OSSTaskDirective 0x{{.*}} <line:{{.*}}:{{.*}}, col:{{.*}}> ompss-2
14+
// CHECK-NEXT: OSSDependClause 0x{{.*}} <col:{{.*}}, col:{{.*}}> <oss syntax>
15+
// CHECK-NEXT: OSSArrayShapingExpr 0x{{.*}} <col:{{.*}}, col:{{.*}}> 'int [4]' lvalue
16+
// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:{{.*}}> 'int *' <LValueToRValue>
17+
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:{{.*}}> 'int *' lvalue ParmVar 0x{{.*}} 'p' 'int *'
18+
// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:{{.*}}, col:{{.*}}> 'int' <LValueToRValue>
19+
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:{{.*}}, col:{{.*}}> 'const int' lvalue Var 0x{{.*}} 'N' 'const int' non_odr_use_constant
20+
// CHECK-NEXT: OSSFirstprivateClause 0x{{.*}} <<invalid sloc>> <implicit>
21+
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:{{.*}}> 'int *' lvalue ParmVar 0x{{.*}} 'p' 'int *'
22+
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:{{.*}}, col:{{.*}}> 'const int' lvalue Var 0x{{.*}} 'N' 'const int' non_odr_use_constant

clang/test/OmpSs/AST/task_depend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void bar1() {
104104
// CHECK-NEXT: OSSArrayShapingExpr {{[a-z0-9]+}} <col:31, col:34> 'int [t][20]' lvalue
105105
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:34> 'int (*)[20]' <ArrayToPointerDecay>
106106
// CHECK-NEXT: DeclRefExpr {{[a-z0-9]+}} <col:34> 'int [10][20]' lvalue Var {{[a-z0-9]+}} 'array' 'int [10][20]'
107+
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:32> 'int':'int' <LValueToRValue>
107108
// CHECK-NEXT: DeclRefExpr {{[a-z0-9]+}} <col:32> 'int':'int' lvalue ParmVar {{[a-z0-9]+}} 't' 'int':'int'
108109
// CHECK-NEXT: OSSArrayShapingExpr {{[a-z0-9]+}} <col:41, col:50> 'int [1][2][3][20]' lvalue
109110
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:50> 'int (*)[20]' <ArrayToPointerDecay>
@@ -121,6 +122,7 @@ void bar1() {
121122
// CHECK-NEXT: OSSArrayShapingExpr {{[a-z0-9]+}} <col:31, col:34> 'int [t]' lvalue
122123
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:34> 'int *' <LValueToRValue>
123124
// CHECK-NEXT: DeclRefExpr {{[a-z0-9]+}} <col:34> 'int *' lvalue Var {{[a-z0-9]+}} 'p' 'int *'
125+
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:32> 'int':'int' <LValueToRValue>
124126
// CHECK-NEXT: DeclRefExpr {{[a-z0-9]+}} <col:32> 'int':'int' lvalue ParmVar {{[a-z0-9]+}} 't' 'int':'int'
125127
// CHECK-NEXT: OSSArrayShapingExpr {{[a-z0-9]+}} <col:37, col:46> 'int [1][2][3]' lvalue
126128
// CHECK-NEXT: ImplicitCastExpr {{[a-z0-9]+}} <col:46> 'int *' <LValueToRValue>

clang/test/OmpSs/Parser/shaping_expr_vs_lambda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void foo1() {
88
{}
99
#pragma oss task depend(in: ([1][2][3]array)[4:5][5])
1010
{}
11-
#pragma oss task depend(in: [1][2]array[4:5]) // expected-error {{OmpSs-2 array section is not allowed in array shaping}}
11+
#pragma oss task depend(in: [1][2]array[4:5]) // expected-error {{OmpSs-2 array section is not allowed here}}
1212
{}
1313
#pragma oss task depend(in: [1][2 : 3]array) // expected-error {{expected ']'}} expected-note {{to match this '['}}
1414
{}

clang/test/OmpSs/Sema/task_depend_shaping_expr1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ void foo() {
55
{
66
int p[10][20][3];
77
int *p1;
8-
#pragma oss task in([12](p[:])) // expected-error {{OmpSs-2 array section is not allowed in array shaping}}
8+
#pragma oss task in([12](p[:])) // expected-error {{OmpSs-2 array section is not allowed here}}
99
{ }
1010
#pragma oss task in([[1]p]p) // expected-error {{OmpSs-2 array shaping is not allowed here}}
1111
{ }
1212
#pragma oss task in([([1]p1)[:]]p) // expected-error {{OmpSs-2 array shaping is not allowed here}}
1313
{ }
14-
#pragma oss task in([(p[0:1])]p) // expected-error {{OmpSs-2 array section is not allowed here}} expected-error {{array shape is not an integer}}
14+
#pragma oss task in([(p[0:1])]p) // expected-error {{OmpSs-2 array section is not allowed here}}
1515
{ }
1616
#pragma oss task in([]p) // expected-error {{expected expression}}
1717
{ }

0 commit comments

Comments
 (0)