[clang] [clang-repl] Restore local out-of-process executor launch (PR #241216)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 02:59:15 PST 2026
https://github.com/anutosh491 created https://github.com/llvm/llvm-project/pull/241216
We should use a socket pair and `socket:adopt` to match llvm-jitlink-executor’s current connection protocol.
>From 459b714c192ce2c5be7204d1c15c1300ab01cae6 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Wed, 11 Nov 2026 16:25:45 +0530
Subject: [PATCH] [clang-repl] Restore local out-of-process executor launch
---
.../OrcIncrementalExecutorBuilder.cpp | 32 ++++++++-----------
.../OutOfProcessInterpreterTests.cpp | 1 +
2 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/clang/lib/Interpreter/OrcIncrementalExecutorBuilder.cpp b/clang/lib/Interpreter/OrcIncrementalExecutorBuilder.cpp
index 89db2d71197a0a..a03291f3487ddb 100644
--- a/clang/lib/Interpreter/OrcIncrementalExecutorBuilder.cpp
+++ b/clang/lib/Interpreter/OrcIncrementalExecutorBuilder.cpp
@@ -187,28 +187,25 @@ launchExecutor(llvm::StringRef ExecutablePath,
llvm::formatv("Specified executor invalid: {0}", ExecutablePath),
llvm::inconvertibleErrorCode());
- constexpr int ReadEnd = 0;
- constexpr int WriteEnd = 1;
+ constexpr int ParentSocket = 0;
+ constexpr int ChildSocket = 1;
- // Pipe FDs.
- int ToExecutor[2];
- int FromExecutor[2];
+ int Sockets[2];
uint32_t ChildPID;
- // Create pipes to/from the executor..
- if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)
+ // Create a socket pair to communicate with the executor.
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, Sockets) != 0)
return llvm::make_error<llvm::StringError>(
- "Unable to create pipe for executor", llvm::inconvertibleErrorCode());
+ "Unable to create socket for executor", llvm::inconvertibleErrorCode());
ChildPID = fork();
if (ChildPID == 0) {
// In the child...
- // Close the parent ends of the pipes
- close(ToExecutor[WriteEnd]);
- close(FromExecutor[ReadEnd]);
+ // Close the parent socket.
+ close(Sockets[ParentSocket]);
if (CustomizeFork)
CustomizeFork();
@@ -219,10 +216,8 @@ launchExecutor(llvm::StringRef ExecutablePath,
ExecutorPath = std::make_unique<char[]>(ExecutablePath.size() + 1);
strcpy(ExecutorPath.get(), ExecutablePath.data());
- std::string FDSpecifierStr("filedescs=");
- FDSpecifierStr += llvm::utostr(ToExecutor[ReadEnd]);
- FDSpecifierStr += ',';
- FDSpecifierStr += llvm::utostr(FromExecutor[WriteEnd]);
+ std::string FDSpecifierStr("socket:adopt=");
+ FDSpecifierStr += llvm::utostr(Sockets[ChildSocket]);
FDSpecifier = std::make_unique<char[]>(FDSpecifierStr.size() + 1);
strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());
}
@@ -237,15 +232,14 @@ launchExecutor(llvm::StringRef ExecutablePath,
}
// else we're the parent...
- // Close the child ends of the pipes
- close(ToExecutor[ReadEnd]);
- close(FromExecutor[WriteEnd]);
+ // Close the child socket.
+ close(Sockets[ChildSocket]);
auto EPCOrErr =
llvm::orc::SimpleRemoteEPC::Create<llvm::orc::FDSimpleRemoteEPCTransport>(
std::make_unique<llvm::orc::DynamicThreadPoolTaskDispatcher>(
std::nullopt),
- FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
+ Sockets[ParentSocket], Sockets[ParentSocket]);
if (!EPCOrErr)
return EPCOrErr.takeError();
return std::make_pair(std::move(*EPCOrErr), ChildPID);
diff --git a/clang/unittests/Interpreter/OutOfProcessInterpreterTests.cpp b/clang/unittests/Interpreter/OutOfProcessInterpreterTests.cpp
index f67ad02d918c64..b6fcc36cafd781 100644
--- a/clang/unittests/Interpreter/OutOfProcessInterpreterTests.cpp
+++ b/clang/unittests/Interpreter/OutOfProcessInterpreterTests.cpp
@@ -183,6 +183,7 @@ class OutOfProcessInterpreterTest : public InterpreterTestBase {
}
static void SetUpTestSuite() {
+ InterpreterTestBase::SetUpTestSuite();
if (!HostSupportsOutOfProcessJIT())
GTEST_SKIP() << "Host does not support out-of-process JIT";
More information about the cfe-commits
mailing list