[flang] [lld] [libcxx] [clang] [mlir] [compiler-rt] [openmp] [llvm] [flang] include sys/wait.h for EXECUTE_COMMAND_LINE (PR #77675)

2024-01-10 Thread Dan McGregor via cfe-commits

https://github.com/dankm updated https://github.com/llvm/llvm-project/pull/77675

>From 588e279c3a1c4dcbea9c2d262848eb1d7d49d0d2 Mon Sep 17 00:00:00 2001
From: Dan McGregor 
Date: Wed, 10 Jan 2024 13:33:37 -0600
Subject: [PATCH] [flang] include sys/wait.h for EXECUTE_COMMAND_LINE

Linux defines WEXITSTATUS in stdlib.h, but at least FreeBSD and NetBSD
only define it in sys/wait.h. Include this header unconditionally, since
it is required on the BSDs and should be harmless on other platforms.
---
 flang/runtime/execute.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flang/runtime/execute.cpp b/flang/runtime/execute.cpp
index 48773ae8114b0b..246495dd4954ad 100644
--- a/flang/runtime/execute.cpp
+++ b/flang/runtime/execute.cpp
@@ -21,6 +21,7 @@
 #include 
 #else
 #include 
+#include 
 #include 
 #endif
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [clang-tools-extra] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2024-01-10 Thread Dan McGregor via cfe-commits


@@ -0,0 +1,206 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor , const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator ) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator ) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};

dankm wrote:

Created #77675 for this.

https://github.com/llvm/llvm-project/pull/74077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [clang-tools-extra] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2024-01-10 Thread Dan McGregor via cfe-commits


@@ -0,0 +1,206 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor , const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator ) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator ) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};

dankm wrote:

Linux defines WEXITSTATUS in stdlib.h (and therefore cstdlib), but at least 
FreeBSD and NetBSD require including sys/wait.h.

It should be harmless to always include sys/wait.h, so I'd suggest doing that.

https://github.com/llvm/llvm-project/pull/74077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names containing dots in all utilities (PR #65812)

2023-10-30 Thread Dan McGregor via cfe-commits

https://github.com/dankm edited https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names containing dots in all utilities (PR #65812)

2023-10-30 Thread Dan McGregor via cfe-commits

https://github.com/dankm edited https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-10-30 Thread Dan McGregor via cfe-commits

dankm wrote:

Sounds good. Everything I want is in the pull request, I'm going to create a 
new pull request to update some tests as we discussed above. I'll update the 
description to be a bit more clear.

Thanks for all help.

https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-10-20 Thread Dan McGregor via cfe-commits

dankm wrote:

Hm. I have "fixup" commits in this branch, should I rebase those, or can we 
squash merge as-is?

https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support target names with dots in more utilities (PR #65812)

2023-10-20 Thread Dan McGregor via cfe-commits

dankm wrote:

No _good_ particular reason. I got hung up on the formatting issues then ran 
out of steam, and busy with $job. I just ran clang-format on this change and it 
came up clean.

And now that I've done that the only reason I have left is I'm unable to merge 
my own changes. Would you mind, @jh7370?

https://github.com/llvm/llvm-project/pull/65812
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits