Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion flang/lib/Semantics/check-coarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,33 @@ 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)}) {
if (expr->Rank() > 1) {
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;
}
}
}
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Semantics/sync-images.f90
Original file line number Diff line number Diff line change
@@ -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