Skip to content

[flang] Test SYNC IMAGES, increase checking #132279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
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