[flang-commits] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

Yi Wu via flang-commits flang-commits at lists.llvm.org
Fri Dec 29 05:22:10 PST 2023


================
@@ -282,4 +282,24 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
   return StatOk;
 }
 
+void RTNAME(System)(const Descriptor &command, const Descriptor *exitstat,
+    const char *sourceFile, int line) {
+  Terminator terminator{sourceFile, line};
+
+  const char *newCmd{EnsureNullTerminated(
+      command.OffsetElement(), command.ElementBytes(), terminator)};
+  int status{std::system(newCmd)};
+
+  if (exitstat) {
+    RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+#ifdef _WIN32
+    StoreLengthToDescriptor(exitstat, status, terminator);
+#else
+    int exitstatVal{WEXITSTATUS(status)};
+    StoreLengthToDescriptor(exitstat, exitstatVal, terminator);
+#endif
+  }
+  FreeMemory((void *)newCmd);
----------------
yi-wu-arm wrote:

added an if condition `newCmd != command.OffsetElement()`

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


More information about the flang-commits mailing list