https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/129252

The actual exec error will not be immediate in the parent when
using the fork path. The error will manifest on the wait. The
ExecuteNoWait test was also expecting the immediate wait.

I hacked up the exit value ExecutionFailed value in ExecuteAndWait,
although arguably the previous behavior was correct. I'm not sure
what the point of the argument is, it's redundant with the return code.

Fixes #129208

>From 7b31093a7ced785c98d5c4c51c39b0f82608e1f8 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <matthew.arsena...@amd.com>
Date: Fri, 28 Feb 2025 21:16:03 +0700
Subject: [PATCH] Support: Fix program error test failures when using fork

The actual exec error will not be immediate in the parent when
using the fork path. The error will manifest on the wait. The
ExecuteNoWait test was also expecting the immediate wait.

I hacked up the exit value ExecutionFailed value in ExecuteAndWait,
although arguably the previous behavior was correct. I'm not sure
what the point of the argument is, it's redundant with the return code.

Fixes #129208
---
 llvm/lib/Support/Program.cpp           |  4 ++++
 llvm/unittests/Support/ProgramTest.cpp | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp
index 181f68cfbb8c3..c8208e4be3175 100644
--- a/llvm/lib/Support/Program.cpp
+++ b/llvm/lib/Support/Program.cpp
@@ -45,6 +45,10 @@ int sys::ExecuteAndWait(StringRef Program, 
ArrayRef<StringRef> Args,
     ProcessInfo Result = Wait(
         PI, SecondsToWait == 0 ? std::nullopt : std::optional(SecondsToWait),
         ErrMsg, ProcStat);
+
+    if (ExecutionFailed && Result.ReturnCode < 0)
+      *ExecutionFailed = true;
+
     return Result.ReturnCode;
   }
 
diff --git a/llvm/unittests/Support/ProgramTest.cpp 
b/llvm/unittests/Support/ProgramTest.cpp
index 47d2e269afe94..ccb154f7fab1a 100644
--- a/llvm/unittests/Support/ProgramTest.cpp
+++ b/llvm/unittests/Support/ProgramTest.cpp
@@ -433,10 +433,19 @@ TEST(ProgramTest, TestExecuteNegative) {
     bool ExecutionFailed;
     ProcessInfo PI = ExecuteNoWait(Executable, argv, std::nullopt, {}, 0,
                                    &Error, &ExecutionFailed);
-    EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
-        << "On error ExecuteNoWait should return an invalid ProcessInfo";
-    EXPECT_TRUE(ExecutionFailed);
-    EXPECT_FALSE(Error.empty());
+
+    if (ExecutionFailed) {
+      EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
+          << "On error ExecuteNoWait should return an invalid ProcessInfo";
+      EXPECT_FALSE(Error.empty());
+    } else {
+      std::string WaitErrMsg;
+      EXPECT_NE(PI.Pid, ProcessInfo::InvalidPid);
+      ProcessInfo WaitPI = Wait(PI, std::nullopt, &WaitErrMsg);
+      EXPECT_EQ(WaitPI.Pid, PI.Pid);
+      EXPECT_LT(WaitPI.ReturnCode, 0);
+      EXPECT_FALSE(WaitErrMsg.empty());
+    }
   }
 
 }

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

Reply via email to