Skip to content

Commit 578d7ad

Browse files
committed
Sema: Improve diagnostics a bit in shaping exprs.
1 parent 58a122a commit 578d7ad

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

+4
Original file line numberDiff line numberDiff line change
@@ -9737,6 +9737,8 @@ def err_oss_section_incomplete_type : Error<
97379737
"section of pointer to incomplete type %0">;
97389738
def err_oss_typecheck_section_not_integer : Error<
97399739
"array section %select{lower bound|length}0 is not an integer">;
9740+
def err_oss_typecheck_shape_not_integer : Error<
9741+
"array shape is not an integer">;
97409742
def err_oss_section_not_subset_of_array : Error<
97419743
"array section must be a subset of the original array">;
97429744
def err_oss_section_length_negative : Error<
@@ -9745,6 +9747,8 @@ def err_oss_section_length_undefined : Error<
97459747
"section length is unspecified and cannot be inferred because subscripted value is %select{not an array|an array of unknown bound}0">;
97469748
def err_oss_typecheck_shaping_base_no_ptr_or_array: Error<
97479749
"shaping expression base is not a pointer or array">;
9750+
def err_oss_shape_incomplete_type : Error<
9751+
"shape of pointer to incomplete type %0">;
97489752
def warn_oss_section_is_char : Warning<"array section %select{lower bound|length}0 is of type 'char'">,
97499753
InGroup<CharSubscript>, DefaultIgnore;
97509754
} // end of OmpSs component.

clang/lib/Sema/SemaExpr.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -4648,6 +4648,9 @@ ExprResult Sema::ActOnOSSArraySectionExpr(Expr *Base, SourceLocation LBLoc,
46484648
auto Res = PerformOmpSsImplicitIntegerConversion(LowerBound->getExprLoc(),
46494649
LowerBound);
46504650
if (Res.isInvalid())
4651+
// FIXME: PerformContextualImplicitConversion doesn't always tell us if it
4652+
// failed and produced a diagnostic.
4653+
// From commit ef6c43dc
46514654
return ExprError(Diag(LowerBound->getExprLoc(),
46524655
diag::err_oss_typecheck_section_not_integer)
46534656
<< 0 << LowerBound->getSourceRange());
@@ -4662,6 +4665,9 @@ ExprResult Sema::ActOnOSSArraySectionExpr(Expr *Base, SourceLocation LBLoc,
46624665
auto Res =
46634666
PerformOmpSsImplicitIntegerConversion(Length->getExprLoc(), Length);
46644667
if (Res.isInvalid())
4668+
// FIXME: PerformContextualImplicitConversion doesn't always tell us if it
4669+
// failed and produced a diagnostic.
4670+
// From commit ef6c43dc
46654671
return ExprError(Diag(Length->getExprLoc(),
46664672
diag::err_oss_typecheck_section_not_integer)
46674673
<< 1 << Length->getSourceRange());
@@ -4792,12 +4798,23 @@ ExprResult Sema::ActOnOSSArrayShapingExpr(Expr *Base, ArrayRef<Expr *> Shapes,
47924798
else if (Type->isArrayType())
47934799
Type = Type->getAsArrayTypeUnsafe()->getElementType();
47944800

4801+
// Handle the case
4802+
// struct S *p; incomplete type
4803+
// [10]p
4804+
if (RequireCompleteType(Base->getExprLoc(), Type,
4805+
diag::err_oss_shape_incomplete_type, Base)) {
4806+
ErrorFound = true;
4807+
}
4808+
47954809
for (int i = Shapes.size() - 1 ; i >= 0; --i) {
47964810
auto Res = PerformOmpSsImplicitIntegerConversion(Shapes[i]->getExprLoc(),
47974811
Shapes[i]);
47984812
if (Res.isInvalid()) {
47994813
ErrorFound = true;
4800-
Diag(Shapes[i]->getExprLoc(), diag::err_oss_typecheck_section_not_integer)
4814+
// FIXME: PerformContextualImplicitConversion doesn't always tell us if it
4815+
// failed and produced a diagnostic.
4816+
// From commit ef6c43dc
4817+
Diag(Shapes[i]->getExprLoc(), diag::err_oss_typecheck_shape_not_integer)
48014818
<< 0 << Shapes[i]->getSourceRange();
48024819
continue;
48034820
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -verify -fompss-2 -ferror-limit 100 -o - %s
2+
3+
4+
void foo(int *p) {
5+
struct S *s; // expected-note 2 {{forward declaration of 'struct S'}}
6+
#pragma oss task depend(in : [4]p[3]) // expected-error {{shaping expression base is not a pointer or array}}
7+
{}
8+
#pragma oss task depend(in : [4]s) // expected-error {{shape of pointer to incomplete type 'struct S'}} expected-error {{array has incomplete element type 'struct S'}}
9+
{}
10+
}

0 commit comments

Comments
 (0)