Skip to content

Commit 58a122a

Browse files
committed
Sema: throw an error if OSSShapingExpr is not a pointer or array
1 parent 825074f commit 58a122a

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

+2
Original file line numberDiff line numberDiff line change
@@ -9743,6 +9743,8 @@ def err_oss_section_length_negative : Error<
97439743
"section length is evaluated to a negative value %0">;
97449744
def err_oss_section_length_undefined : Error<
97459745
"section length is unspecified and cannot be inferred because subscripted value is %select{not an array|an array of unknown bound}0">;
9746+
def err_oss_typecheck_shaping_base_no_ptr_or_array: Error<
9747+
"shaping expression base is not a pointer or array">;
97469748
def warn_oss_section_is_char : Warning<"array section %select{lower bound|length}0 is of type 'char'">,
97479749
InGroup<CharSubscript>, DefaultIgnore;
97489750
} // end of OmpSs component.

clang/lib/Sema/SemaExpr.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -4780,6 +4780,12 @@ ExprResult Sema::ActOnOSSArrayShapingExpr(Expr *Base, ArrayRef<Expr *> Shapes,
47804780
VK_LValue, OK_Ordinary, Base, Shapes, LBLoc, RBLoc);
47814781
}
47824782

4783+
if (!Base->getType()->isPointerType()
4784+
&& !Base->getType()->isArrayType()) {
4785+
Diag(Base->getExprLoc(), diag::err_oss_typecheck_shaping_base_no_ptr_or_array)
4786+
<< Base->getSourceRange();
4787+
}
4788+
47834789
QualType Type = Base->getType();
47844790
if (Type->isPointerType())
47854791
Type = Type->getPointeeType();

clang/test/OmpSs/AST/task_depend.c

+1-23
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ void foo4() {
233233
void foo5(int *p, int n) {
234234
#pragma oss task depend(in : [n + 1][n + 2]p)
235235
{}
236-
#pragma oss task depend(in : [n + 1][n + 2]p[11])
237-
{}
238236
#pragma oss task depend(in : ([n + 1][n + 2]p)[43])
239237
{}
240238
}
@@ -256,27 +254,7 @@ void foo5(int *p, int n) {
256254
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:48> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
257255
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:35> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
258256

259-
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:236:13, col:54>
260-
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:22, col:53>
261-
// CHECK-NEXT: OSSArrayShapingExpr 0x{{[^ ]*}} <col:34, col:52> 'int [n + 1][n + 2]' lvalue
262-
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:48, col:52> 'int' <LValueToRValue>
263-
// CHECK-NEXT: ArraySubscriptExpr 0x{{[^ ]*}} <col:48, col:52> 'int' lvalue
264-
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:48> 'int *' <LValueToRValue>
265-
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:48> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
266-
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:50> 'int' 11
267-
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:35, col:39> 'int' '+'
268-
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:35> 'int' <LValueToRValue>
269-
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:35> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
270-
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:39> 'int' 1
271-
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:42, col:46> 'int' '+'
272-
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:42> 'int' <LValueToRValue>
273-
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:42> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
274-
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:46> 'int' 2
275-
// CHECK-NEXT: OSSFirstprivateClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
276-
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:48> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
277-
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:35> 'int' lvalue ParmVar 0x{{[^ ]*}} 'n' 'int'
278-
279-
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:238:13, col:56>
257+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:236:13, col:56>
280258
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:22, col:55>
281259
// CHECK-NEXT: ArraySubscriptExpr 0x{{[^ ]*}} <col:34, col:54> 'int [n + 2]' lvalue
282260
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:34, col:50> 'int (*)[n + 2]' <ArrayToPointerDecay>

0 commit comments

Comments
 (0)