[flang-commits] [flang] [flang] Add check for definability for Image-selector STAT= specifier #224058 (PR #230031)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Fri Oct 9 06:50:19 PDT 2026


================
@@ -115,10 +115,20 @@ static void CheckTeamType(
 static void CheckTeamStat(
     SemanticsContext &context, const parser::ImageSelectorSpec::Stat &stat) {
   const auto &var{parser::UnwrapRef<parser::Variable>(stat)};
+  auto at{parser::FindSourceLocation(var)};
   if (parser::GetCoindexedNamedObject(var)) {
     context.Say(parser::FindSourceLocation(var), // C931
         "Image selector STAT variable must not be a coindexed "
         "object"_err_en_US);
+  } else if (const auto *expr{GetExpr(context, var)}) {
----------------
eugeneepshteyn wrote:

(This comment was generated with the help of AI)

`StatVariable` also gets `CheckIndexVarRedefine` from `DoForallChecker`, but the image-selector STAT= doesn't, so an active DO, DO CONCURRENT or FORALL index is accepted:

```fortran
subroutine s
  real, save :: c[*]
  real :: r
  integer :: i
  do i = 1, 2
    r = c[1, stat=i]    ! accepted
    sync all (stat=i)   ! error: Cannot redefine DO variable 'i'
  end do
end subroutine
```

Calling `CheckIndexVarRedefine` (a new check) here would cover it; a follow-up is fine too.

https://github.com/llvm/llvm-project/pull/230031


More information about the flang-commits mailing list