Skip to content

Commit 38207a5

Browse files
authored
[flang] Test SYNC IMAGES, increase checking (#132279)
Add a test for the SYNC IMAGES statement, and add a check for invalid image numbers.
1 parent f3991e1 commit 38207a5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

flang/lib/Semantics/check-coarray.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,33 @@ void CoarrayChecker::Leave(const parser::SyncAllStmt &x) {
194194

195195
void CoarrayChecker::Leave(const parser::SyncImagesStmt &x) {
196196
CheckSyncStatList(context_, std::get<std::list<parser::StatOrErrmsg>>(x.t));
197-
198197
const auto &imageSet{std::get<parser::SyncImagesStmt::ImageSet>(x.t)};
199198
if (const auto *intExpr{std::get_if<parser::IntExpr>(&imageSet.u)}) {
200199
if (const auto *expr{GetExpr(context_, *intExpr)}) {
201200
if (expr->Rank() > 1) {
202201
context_.Say(parser::FindSourceLocation(imageSet), // C1174
203202
"An image-set that is an int-expr must be a scalar or a rank-one array"_err_en_US);
204203
}
204+
if (const auto *someInt{
205+
std::get_if<evaluate::Expr<evaluate::SomeInteger>>(&expr->u)};
206+
someInt && evaluate::IsActuallyConstant(*someInt)) {
207+
auto converted{evaluate::Fold(context_.foldingContext(),
208+
evaluate::ConvertToType<evaluate::SubscriptInteger>(
209+
common::Clone(*someInt)))};
210+
if (const auto *cst{
211+
evaluate::UnwrapConstantValue<evaluate::SubscriptInteger>(
212+
converted)}) {
213+
for (auto elt : cst->values()) {
214+
auto n{elt.ToInt64()};
215+
if (n < 1) {
216+
context_.Say(parser::FindSourceLocation(imageSet),
217+
"Image number %jd in the image-set is not valid"_err_en_US,
218+
std::intmax_t{n});
219+
break;
220+
}
221+
}
222+
}
223+
}
205224
}
206225
}
207226
}

flang/test/Semantics/sync-images.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!RUN: %python %S/test_errors.py %s %flang_fc1
2+
integer twod(1,1)
3+
sync images (*) ! ok
4+
!ERROR: An image-set that is an int-expr must be a scalar or a rank-one array
5+
sync images (twod)
6+
!ERROR: Must have INTEGER type, but is REAL(4)
7+
sync images (3.14159)
8+
!ERROR: Image number -1 in the image-set is not valid
9+
sync images (-1)
10+
!ERROR: Image number -1 in the image-set is not valid
11+
sync images ([2, -1, 3])
12+
end

0 commit comments

Comments
 (0)