From a525f56c391d221999f3186585238d67319ba5ba Mon Sep 17 00:00:00 2001 From: Tarun Prabhu Date: Mon, 8 Jan 2024 15:53:06 -0700 Subject: [PATCH 1/3] [tools] Fix not utility to work on iOS This addresses issue #77137. The implementation uses posix_spawn on iOS but std::system elsewhere. --- tools/CMakeLists.txt | 10 +--------- tools/not.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2debdfb61d..e8812d8265 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -40,12 +40,4 @@ else() llvm_add_host_executable(build-timeit timeit timeit.c) endif() -# FIXME: the iOS buildbots can't build this since it uses `std::system`, but -# since we don't support Fortram on the iOS bots and this utility is only used -# by Fortran tests, it effectively "reverts to green", without entirely -# reverting the patch. -# -# See: https://github.com/llvm/llvm-project/issues/77137 -if(TEST_SUITE_FORTRAN) - add_executable(not ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp) -endif() \ No newline at end of file +add_executable(not ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp) diff --git a/tools/not.cpp b/tools/not.cpp index 8d83e084ac..8ea4ae25ee 100644 --- a/tools/not.cpp +++ b/tools/not.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -24,7 +26,11 @@ #include #endif -int main(int argc, const char **argv) { +#ifdef __APPLE__ +#include +#endif + +int main(int argc, char* const* argv) { bool expectCrash = false; ++argv; @@ -49,13 +55,22 @@ int main(int argc, const char **argv) { if (argc == 0) return 1; + int result; +#if !defined(TARGET_OS_IPHONE) std::stringstream ss; ss << argv[0]; for (int i = 1; i < argc; ++i) ss << " " << argv[i]; std::string cmd = ss.str(); - - int result = std::system(cmd.c_str()); + result = std::system(cmd.c_str()); +#else + char* const* environ = NULL; + pid_t pid; + if (posix_spawn(&pid, argv[0], NULL, NULL, argv, environ)) + return EXIT_FAILURE; + if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1) + return EXIT_FAILURE; +#endif int retcode = 0; int signal = 0; From bf2fac602d8355d07bea9017a65a938b8832b4d6 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu Date: Tue, 9 Jan 2024 09:44:35 -0700 Subject: [PATCH 2/3] Add header files only necesary on iOS to the ifdef block. Address other comments from the code review. --- tools/not.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/not.cpp b/tools/not.cpp index 8ea4ae25ee..e5c1a9b89b 100644 --- a/tools/not.cpp +++ b/tools/not.cpp @@ -17,8 +17,6 @@ #include #include #include -#include -#include #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -27,6 +25,8 @@ #endif #ifdef __APPLE__ +#include +#include #include #endif @@ -64,9 +64,8 @@ int main(int argc, char* const* argv) { std::string cmd = ss.str(); result = std::system(cmd.c_str()); #else - char* const* environ = NULL; pid_t pid; - if (posix_spawn(&pid, argv[0], NULL, NULL, argv, environ)) + if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL)) return EXIT_FAILURE; if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1) return EXIT_FAILURE; From 428adc22baa77d7e12909a25c2cdaa4bb7e14a75 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu Date: Thu, 11 Jan 2024 07:35:25 -0700 Subject: [PATCH 3/3] Fix include file path on Apple --- tools/not.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/not.cpp b/tools/not.cpp index e5c1a9b89b..ce296b9bb5 100644 --- a/tools/not.cpp +++ b/tools/not.cpp @@ -26,7 +26,7 @@ #ifdef __APPLE__ #include -#include +#include #include #endif