Skip to content

Commit acaac0b

Browse files
committed
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
1 parent a0540e6 commit acaac0b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

llvm/lib/Support/Program.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args,
4545
ProcessInfo Result = Wait(
4646
PI, SecondsToWait == 0 ? std::nullopt : std::optional(SecondsToWait),
4747
ErrMsg, ProcStat);
48+
49+
if (ExecutionFailed && Result.ReturnCode < 0)
50+
*ExecutionFailed = true;
51+
4852
return Result.ReturnCode;
4953
}
5054

llvm/unittests/Support/ProgramTest.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,19 @@ TEST(ProgramTest, TestExecuteNegative) {
433433
bool ExecutionFailed;
434434
ProcessInfo PI = ExecuteNoWait(Executable, argv, std::nullopt, {}, 0,
435435
&Error, &ExecutionFailed);
436-
EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
437-
<< "On error ExecuteNoWait should return an invalid ProcessInfo";
438-
EXPECT_TRUE(ExecutionFailed);
439-
EXPECT_FALSE(Error.empty());
436+
437+
if (ExecutionFailed) {
438+
EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
439+
<< "On error ExecuteNoWait should return an invalid ProcessInfo";
440+
EXPECT_FALSE(Error.empty());
441+
} else {
442+
std::string WaitErrMsg;
443+
EXPECT_NE(PI.Pid, ProcessInfo::InvalidPid);
444+
ProcessInfo WaitPI = Wait(PI, std::nullopt, &WaitErrMsg);
445+
EXPECT_EQ(WaitPI.Pid, PI.Pid);
446+
EXPECT_LT(WaitPI.ReturnCode, 0);
447+
EXPECT_FALSE(WaitErrMsg.empty());
448+
}
440449
}
441450

442451
}

0 commit comments

Comments
 (0)