[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


================
@@ -93,10 +100,38 @@ RT_API_ATTRS void Terminator::CrashHeader() const {
       sourceFileName_, sourceLine_);
 }
 
-// TODO: These will be defined in the coarray runtime library
-RT_API_ATTRS void NotifyOtherImagesOfNormalEnd() {}
-RT_API_ATTRS void NotifyOtherImagesOfFailImageStatement() {}
-RT_API_ATTRS void NotifyOtherImagesOfErrorTermination() {}
+void ExitHandler::Configure(bool mifEnabled) {
+  multiImageFeatureEnabled = mifEnabled;
+}
+
+void ExitHandler::NormalExit(int exitCode) {
+  if (multiImageFeatureEnabled)
+    NotifyOtherImagesOfErrorTermination(exitCode);
+  else
+    std::exit(exitCode);
+}
+
+void ExitHandler::ErrorExit(int exitCode) {
+  if (multiImageFeatureEnabled)
+    SynchronizeImagesOfNormalEnd(exitCode);
+  else
+    std::exit(exitCode);
+}
----------------
bonachea wrote:

The callback invocations this version of the code are backwards. I assume you instead meant the opposite, as amended below.

Additionally: As previously mentioned the callbacks registered into `normalEndCallback` and `errorCallback` by the PRIF support will never return. However if (for whatever reason) `multiImageFeatureEnabled` is set and the callbacks have not been registered (or have not been registered to PRIF calls) then this property might not hold. As such I suggest we program this more defensively, as shown below.

Finally, this change should also enable us to declare these functions as `[[noreturn]]`.

```suggestion
[[noreturn]]
void ExitHandler::NormalExit(int exitCode) {
  if (multiImageFeatureEnabled)
    SynchronizeImagesOfNormalEnd(exitCode); // might never return

  std::exit(exitCode);
}

[[noreturn]]
void ExitHandler::ErrorExit(int exitCode) {
  if (multiImageFeatureEnabled)
    NotifyOtherImagesOfErrorTermination(exitCode); // might never return

  std::exit(exitCode);
}
```

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


More information about the flang-commits mailing list