[flang-commits] [flang] [flang][Semantics] Adding check integer kind on STAT= specifier #230463 (PR #231103)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Mon Oct 12 18:46:39 PDT 2026
================
@@ -145,6 +153,15 @@ static void CheckSyncStat(SemanticsContext &context,
context.Say( // C1172
"The stat-variable in a sync-stat-list may not be repeated"_err_en_US);
}
+ if (const auto *expr{GetExpr(context, stat)})
+ if (auto type{expr->GetType()}; type &&
+ type->category() == TypeCategory::Integer &&
+ type->kind() < 2 &&
+ context.ShouldWarn(
+ common::LanguageFeature::StatKind)) { // F2023 9.7.4 p1
+ context.Say(
+ "The stat-variable must have an integer kind of at least 16-bit"_warn_en_US);
+ }
----------------
eugeneepshteyn wrote:
(This comment was generated with the help of AI)
This misses the most common STAT= sites: with `-pedantic`, ALLOCATE, DEALLOCATE and FORM TEAM get no warning.
```fortran
program p
use iso_fortran_env, only: team_type
integer(1) :: s
integer, allocatable :: a(:)
type(team_type) :: t
sync all(stat=s) ! warns
allocate(a(3), stat=s) ! no warning
deallocate(a, stat=s) ! no warning
form team(1, t, stat=s) ! no warning
end program
```
`flang -fsyntax-only -pedantic` warns only on line 6.
F2023 9.7.4 p1 applies to every *stat-variable*, not just the ones in sync-stat-lists, image selectors and EVENT/NOTIFY WAIT. All of these sites except the image selector reach semantics through `parser::StatOrErrmsg`, so doing the check once per `StatOrErrmsg`, plus the image selector, would cover them all and replace the three copies in this file. IOSTAT= is a bare `StatVariable` outside `StatOrErrmsg`, so it would not be affected. The test should then cover ALLOCATE, DEALLOCATE and FORM TEAM too.
https://github.com/llvm/llvm-project/pull/231103
More information about the flang-commits
mailing list