[flang] Test SYNC IMAGES, increase checking (#132279)
Add a test for the SYNC IMAGES statement, and add a check for invalid image numbers.
This commit is contained in:
parent
f3991e10bb
commit
38207a52a7
2 changed files with 32 additions and 1 deletions
|
|
@ -194,7 +194,6 @@ void CoarrayChecker::Leave(const parser::SyncAllStmt &x) {
|
|||
|
||||
void CoarrayChecker::Leave(const parser::SyncImagesStmt &x) {
|
||||
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
|
||||
|
||||
const auto &imageSet{std::get<parser::SyncImagesStmt::ImageSet>(x.t)};
|
||||
if (const auto *intExpr{std::get_if<parser::IntExpr>(&imageSet.u)}) {
|
||||
if (const auto *expr{GetExpr(context_, *intExpr)}) {
|
||||
|
|
@ -202,6 +201,26 @@ void CoarrayChecker::Leave(const parser::SyncImagesStmt &x) {
|
|||
context_.Say(parser::FindSourceLocation(imageSet), // C1174
|
||||
"An image-set that is an int-expr must be a scalar or a rank-one array"_err_en_US);
|
||||
}
|
||||
if (const auto *someInt{
|
||||
std::get_if<evaluate::Expr<evaluate::SomeInteger>>(&expr->u)};
|
||||
someInt && evaluate::IsActuallyConstant(*someInt)) {
|
||||
auto converted{evaluate::Fold(context_.foldingContext(),
|
||||
evaluate::ConvertToType<evaluate::SubscriptInteger>(
|
||||
common::Clone(*someInt)))};
|
||||
if (const auto *cst{
|
||||
evaluate::UnwrapConstantValue<evaluate::SubscriptInteger>(
|
||||
converted)}) {
|
||||
for (auto elt : cst->values()) {
|
||||
auto n{elt.ToInt64()};
|
||||
if (n < 1) {
|
||||
context_.Say(parser::FindSourceLocation(imageSet),
|
||||
"Image number %jd in the image-set is not valid"_err_en_US,
|
||||
std::intmax_t{n});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
flang/test/Semantics/sync-images.f90
Normal file
12
flang/test/Semantics/sync-images.f90
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
!RUN: %python %S/test_errors.py %s %flang_fc1
|
||||
integer twod(1,1)
|
||||
sync images (*) ! ok
|
||||
!ERROR: An image-set that is an int-expr must be a scalar or a rank-one array
|
||||
sync images (twod)
|
||||
!ERROR: Must have INTEGER type, but is REAL(4)
|
||||
sync images (3.14159)
|
||||
!ERROR: Image number -1 in the image-set is not valid
|
||||
sync images (-1)
|
||||
!ERROR: Image number -1 in the image-set is not valid
|
||||
sync images ([2, -1, 3])
|
||||
end
|
||||
Loading…
Reference in a new issue