[flang-commits] [flang] [llvm] [flang][MIF] Adding Stop and ErrorStop operations (PR #166787)
Dan Bonachea via flang-commits
flang-commits at lists.llvm.org
Tue Jan 13 21:33:05 PST 2026
================
@@ -144,7 +147,7 @@ static void EndPause() {
std::fflush(nullptr);
if (std::fgetc(stdin) == EOF) {
CloseAllExternalUnits("PAUSE statement");
- std::exit(EXIT_SUCCESS);
+ Fortran::runtime::exitHandler.NormalExit(EXIT_SUCCESS);
----------------
bonachea wrote:
The `PAUSE` statement was removed after Fortran 90, prior to the Fortran 2008 introduction of multi-image and a distinction between normal vs error termination. Even in F90 it was unspecified what happens for this case (where execution is not "resumed").
This implementation of `PAUSE` seems currently unsuitable for multi-image execution, because relying on `stdin` behavior is generally non-portable when there are two or more images. The standard itself says that `INPUT_UNIT` is only connected on the first image, but the `Fortran::runtime::io::IsATerminal` predicate called by `StartPause()` is not currently sensitive to image number.
All that being said, this case feels to me like it should be a non-collective (Error) exit. That ensures that if/when `Fortran::runtime::io::IsATerminal` is updated to return false for image index > 1, an EOF detected by image 1 within `EndPause()` would terminate the whole job as intended, rather than initiating normal termination from only image 1 and then (likely) deadlocking.
```suggestion
Fortran::runtime::exitHandler.ErrorExit(EXIT_SUCCESS);
```
https://github.com/llvm/llvm-project/pull/166787
More information about the flang-commits
mailing list