Skip to content

Commit 07c25fc

Browse files
committed
Sema: Forbid more than one-level OSSArraySections with pointers
Fixes llvm#24
1 parent 4d9b56a commit 07c25fc

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

+2
Original file line numberDiff line numberDiff line change
@@ -9745,6 +9745,8 @@ def err_oss_section_length_negative : Error<
97459745
"section length is evaluated to a negative value %0">;
97469746
def err_oss_section_length_undefined : Error<
97479747
"section length is unspecified and cannot be inferred because subscripted value is %select{not an array|an array of unknown bound}0">;
9748+
def err_oss_section_only_one_pointer_level : Error<
9749+
"pointer types only allow one-level array sections">;
97489750
def err_oss_typecheck_shaping_base_no_ptr_or_array: Error<
97499751
"shaping expression base is not a pointer or array">;
97509752
def err_oss_shape_incomplete_type : Error<

clang/lib/Sema/SemaExpr.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -4635,6 +4635,11 @@ ExprResult Sema::ActOnOSSArraySectionExpr(Expr *Base, SourceLocation LBLoc,
46354635
QualType OriginalTy = OSSArraySectionExpr::getBaseOriginalType(Base);
46364636
QualType ResultTy;
46374637
if (OriginalTy->isAnyPointerType()) {
4638+
if (const auto *OASE = dyn_cast<OSSArraySectionExpr>(Base)) {
4639+
Diag(OASE->getExprLoc(), diag::err_oss_section_only_one_pointer_level)
4640+
<< OASE->getSourceRange();
4641+
return ExprError();
4642+
}
46384643
ResultTy = OriginalTy->getPointeeType();
46394644
} else if (OriginalTy->isArrayType()) {
46404645
ResultTy = OriginalTy->getAsArrayTypeUnsafe()->getElementType();

clang/test/OmpSs/Sema/task_depend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main(int argc, char **argv, char *env[]) {
5151
#pragma oss task depend(in:argv[argv[:2]:1]) // expected-error {{OmpSs-2 array section is not allowed here}}
5252
#pragma oss task depend(in:argv[0:][:]) // expected-error {{section length is unspecified and cannot be inferred because subscripted value is not an array}}
5353
#pragma oss task depend(in:env[0:][:]) // expected-error {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}}
54-
#pragma oss task depend(in : argv[ : argc][1 : argc - 1])
54+
#pragma oss task depend(in : argv[ : argc][1 : argc - 1]) // expected-error {{pointer types only allow one-level array sections}}
5555
#pragma oss task depend(in : arr[0])
5656
#pragma oss task depend(, // expected-error {{expected 'in', 'out', 'inout' or 'weak' in OmpSs-2 clause 'depend'}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-warning {{missing ':' after dependency type - ignoring}}
5757
#pragma oss task depend(, : // expected-error {{expected 'in', 'out', 'inout' or 'weak' in OmpSs-2 clause 'depend'}} expected-error {{expected ')'}} expected-note {{to match this '('}}

0 commit comments

Comments
 (0)