[flang-commits] [flang] [llvm] [flang][MIF] Adding Stop and ErrorStop operations (PR #166787)

Dan Bonachea via flang-commits flang-commits at lists.llvm.org
Mon Dec 15 20:23:10 PST 2025


================

----------------
bonachea wrote:

As previously discussed, some of the current usage of `NotifyOtherImagesOfNormalEnd` and `NotifyOtherImagesOfErrorTermination` elsewhere inside `flang-rt` is probably incorrect, at least for the usage intended in this PR. 

Most egregiously, the registration of `NotifyOtherImagesOfNormalEnd` as a `std::atexit` handler inside `RTNAME(ProgramStart)` in lib/runtime/main.cpp is almost certainly wrong.  This "just works" before this PR because the callback is currently a no-op, hence it makes no difference whether or when it runs. However this PR converts the `NotifyOtherImagesOfNormalEnd` callback into a multi-image parallel barrier synchronization (as required by multi-image `STOP` and implemented in `prif_stop`), and with that change this usage seems problematic for many reasons. For example it means a call to `std::exit` from inside a C++ library linked into the program would suddenly invoke a Fortran-style multi-image parallel barrier. I'm not sure what the right behavior is for that particular case, but silently converting all calls to `std::exit` into a collective barrier synchronization seems at least surprising, and at worst likely to produce confusing deadlocks in practice. 

In a related example, the `RTNAME(StopStatement)/RTNAME(StopStatementText)` functions do not appear to invoke `NotifyOtherImagesOfErrorTermination` at all for the `ERROR STOP` case; they instead print some output and then call `std::exit` (which IIUC could  deadlock upon a non-collective call, for the reason described above). This particular case _might_ become unreachable in `-fcoarray` compilation in the current version of this PR, but @jeanPerier raised the possibility that we might support linking of objects with/without `-fcoarray`, in which case these calls could presumably still arise in a multi-image program. In any case there are other calls to `std::exit` elsewhere in flang-rt's stop.cpp (e.g. in the Fortran [extension intrinsic](https://gcc.gnu.org/onlinedocs/gfortran/EXIT.html) `EXIT()`, where it's unclear whether this should include a `STOP`-style image synchronization).

Do we want to try and clean any of this up as part of this PR, or in a subsequent PR? 





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


More information about the flang-commits mailing list