https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/175910

>From 0a60a2c20006972993bac10bda999910a1d09099 Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Wed, 7 Oct 2026 11:54:57 +0530
Subject: [PATCH] [clang-repl] Drop ORC link dependencies from Emscripten
 builds

---
 .../clang/Interpreter/IncrementalExecutor.h   |  4 +++
 clang/include/clang/Interpreter/Interpreter.h |  2 --
 clang/lib/Interpreter/CMakeLists.txt          | 29 +++++++++--------
 clang/lib/Interpreter/IncrementalExecutor.cpp | 12 ++-----
 clang/lib/Interpreter/Interpreter.cpp         |  4 +--
 clang/lib/Interpreter/Wasm.cpp                | 31 +++++++++++++++++++
 clang/unittests/Interpreter/CMakeLists.txt    |  2 +-
 .../Interpreter/ExceptionTests/CMakeLists.txt | 24 +++++++++++---
 .../InterpreterExceptionTest.cpp              |  6 ++++
 .../Interpreter/InterpreterExtensionsTest.cpp |  3 ++
 10 files changed, 85 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Interpreter/IncrementalExecutor.h 
b/clang/include/clang/Interpreter/IncrementalExecutor.h
index 913da9230a9473..0ff07aaf416ba4 100644
--- a/clang/include/clang/Interpreter/IncrementalExecutor.h
+++ b/clang/include/clang/Interpreter/IncrementalExecutor.h
@@ -33,6 +33,8 @@ class Compilation;
 
 class IncrementalExecutorBuilder {
 public:
+  IncrementalExecutorBuilder();
+
   /// Indicates whether out-of-process JIT execution is enabled.
   bool IsOutOfProcess = false;
   /// Path to the out-of-process JIT executor.
@@ -52,8 +54,10 @@ class IncrementalExecutorBuilder {
   std::optional<llvm::CodeModel::Model> CM = std::nullopt;
   /// An optional external IncrementalExecutor
   std::unique_ptr<IncrementalExecutor> IE;
+#ifndef __EMSCRIPTEN__
   /// An optional external orc jit builder
   std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
+#endif
   /// A default callback that can be used in the IncrementalCompilerBuilder to
   /// retrieve the path to the orc runtime.
   std::function<llvm::Error(const driver::Compilation &)>
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index c2622b23d5d9ce..0dd1e52749b4f2 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,8 +20,6 @@
 #include "clang/Interpreter/Value.h"
 
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include <cstdint>
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 01d3295d1ac30d..95bac67e1b9dbb 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -3,35 +3,39 @@ set(LLVM_LINK_COMPONENTS
    native
    MC
    Option
-   OrcJit
-   OrcDebugging
-   OrcShared
-   OrcTargetProcess
    Support
    Target
    TargetParser
    TransformUtils
    )
 
-if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
-  set(WASM_SRC Wasm.cpp)
-  set(WASM_LINK lldWasm)
-  set(COMMON_LINK lldCommon)
+if (EMSCRIPTEN)
+  if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS)
+    message(FATAL_ERROR "Building clangInterpreter for Emscripten requires 
lld")
+  endif()
+  set(EXECUTOR_SOURCES Wasm.cpp)
+  set(EXECUTOR_LIBS lldWasm lldCommon)
+else()
+  list(APPEND LLVM_LINK_COMPONENTS
+    OrcJit
+    OrcDebugging
+    OrcShared
+    OrcTargetProcess
+    )
+  set(EXECUTOR_SOURCES IncrementalExecutor.cpp OrcIncrementalExecutor.cpp)
 endif()
 
 add_clang_library(clangInterpreter
   DeviceOffload.cpp
   CodeCompletion.cpp
   IncrementalAction.cpp
-  IncrementalExecutor.cpp
-  OrcIncrementalExecutor.cpp
   IncrementalParser.cpp
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
   Value.cpp
   InterpreterValuePrinter.cpp
-  ${WASM_SRC}
+  ${EXECUTOR_SOURCES}
   PARTIAL_SOURCES_INTENDED
 
   DEPENDS
@@ -51,8 +55,7 @@ add_clang_library(clangInterpreter
   clangParse
   clangSema
   clangSerialization
-  ${WASM_LINK}
-  ${COMMON_LINK}
+  ${EXECUTOR_LIBS}
   )
 
 if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 5d01ba47742699..e356ce6d9fe99c 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -12,9 +12,6 @@
 
 #include "clang/Interpreter/IncrementalExecutor.h"
 #include "OrcIncrementalExecutor.h"
-#ifdef __EMSCRIPTEN__
-#include "Wasm.h"
-#endif // __EMSCRIPTEN__
 
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Config/config.h"
@@ -84,6 +81,7 @@ static void *getEmuTLSGetAddressPtr() { return nullptr; }
 #endif
 
 namespace clang {
+IncrementalExecutorBuilder::IncrementalExecutorBuilder() = default;
 IncrementalExecutorBuilder::~IncrementalExecutorBuilder() = default;
 
 static llvm::Expected<llvm::orc::JITTargetMachineBuilder>
@@ -427,12 +425,8 @@ 
IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC,
   }
 
   llvm::Error Err = llvm::Error::success();
-  std::unique_ptr<IncrementalExecutor> Executor;
-#ifdef __EMSCRIPTEN__
-  Executor = std::make_unique<WasmIncrementalExecutor>(Err);
-#else
-  Executor = std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err);
-#endif
+  std::unique_ptr<IncrementalExecutor> Executor =
+      std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err);
 
   if (Err)
     return std::move(Err);
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 40fbc83db9107c..0cfbe1410e2299 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -45,9 +45,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ModuleCache.h"
 #include "clang/Serialization/ObjectFilePCHContainerReader.h"
-#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
-#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index 573c8910d3a414..2bc90a8d8c88ae 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -61,6 +61,37 @@ bool link(llvm::ArrayRef<const char *> args, 
llvm::raw_ostream &stdoutOS,
 
 namespace clang {
 
+IncrementalExecutorBuilder::IncrementalExecutorBuilder() = default;
+IncrementalExecutorBuilder::~IncrementalExecutorBuilder() = default;
+
+llvm::Expected<std::unique_ptr<IncrementalExecutor>>
+IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC,
+                                   const clang::TargetInfo &TI) {
+  if (IE)
+    return std::move(IE);
+
+  if (IsOutOfProcess)
+    return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                   "Out-of-process execution is not supported "
+                                   "by the WebAssembly executor");
+
+  llvm::Error Err = llvm::Error::success();
+  std::unique_ptr<IncrementalExecutor> Executor =
+      std::make_unique<WasmIncrementalExecutor>(Err);
+  if (Err)
+    return std::move(Err);
+  return std::move(Executor);
+}
+
+llvm::Error IncrementalExecutorBuilder::UpdateOrcRuntimePath(
+    const clang::driver::Compilation &C) {
+  if (IsOutOfProcess)
+    return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                   "Out-of-process execution is not supported "
+                                   "by the WebAssembly executor");
+  return llvm::Error::success();
+}
+
 WasmIncrementalExecutor::WasmIncrementalExecutor(llvm::Error &Err) {
   llvm::ErrorAsOutParameter EAO(&Err);
 
diff --git a/clang/unittests/Interpreter/CMakeLists.txt 
b/clang/unittests/Interpreter/CMakeLists.txt
index 6d999104054c30..60cea441ab4480 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -3,7 +3,7 @@ set(LLVM_COMPONENTS_TO_LINK
   ""
   )
 set(LLVM_LIBS_TO_LINK
-  ""
+  LLVMTestingSupport
   )
 set(CLANG_LIBS_TO_LINK
   clangInterpreter
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt 
b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index dfd94d8e6442c4..800824140a22e2 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,6 +3,11 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
+set(INTERPRETER_EXCEPTION_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Core Support)
+if(NOT EMSCRIPTEN)
+  list(APPEND INTERPRETER_EXCEPTION_COMPONENTS OrcJIT)
+endif()
+
 add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
   EXPORT_SYMBOLS
@@ -14,11 +19,22 @@ 
add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
   clangFrontend
 
   LLVM_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
-  Core
-  OrcJIT
-  Support
+  ${INTERPRETER_EXCEPTION_COMPONENTS}
   )
 
 llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
 add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)
+
+if(EMSCRIPTEN)
+  get_target_property(LINKED_LIBS ClangReplInterpreterExceptionTests 
LINK_LIBRARIES)
+  list(REMOVE_ITEM LINKED_LIBS LLVMSupport)
+  set_target_properties(ClangReplInterpreterExceptionTests PROPERTIES
+    LINK_LIBRARIES "${LINKED_LIBS}"
+    )
+  target_link_options(ClangReplInterpreterExceptionTests PRIVATE
+    "SHELL:-s MAIN_MODULE=1"
+    "SHELL:-s ALLOW_MEMORY_GROWTH=1"
+    "SHELL:-s STACK_SIZE=32mb"
+    "SHELL:-s INITIAL_MEMORY=128mb"
+    )
+endif()
diff --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index c8522e91602768..c0272d5bd0c555 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -67,6 +67,10 @@ TEST(InterpreterExceptionTest, CatchException) {
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTargetAsmPrinter();
 
+#ifdef __EMSCRIPTEN__
+  // The WebAssembly executor does not configure exception handling yet.
+  GTEST_SKIP();
+#else
   {
     auto J = llvm::orc::LLJITBuilder().create();
     if (!J) {
@@ -78,6 +82,8 @@ TEST(InterpreterExceptionTest, CatchException) {
     }
   }
 
+#endif
+
 #define Stringify(s) Stringifyx(s)
 #define Stringifyx(s) #s
 
diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp 
b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
index 13825f2cbdddfd..642869e124b8bd 100644
--- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
@@ -65,6 +65,7 @@ class InterpreterExtensionsTest : public InterpreterTestBase {
   }
 };
 
+#ifndef __EMSCRIPTEN__
 class CustomJBInterpreter : public Interpreter {
   using CustomJITBuilderCreatorFunction =
       
std::function<llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>()>;
@@ -138,6 +139,8 @@ TEST_F(InterpreterExtensionsTest, CustomCrossJIT) {
   EXPECT_EQ(1U, Objs.size());
 }
 
+#endif // __EMSCRIPTEN__
+
 TEST_F(InterpreterExtensionsTest, CustomIncrementalExecutor) {
   struct RecordingIncrementalExecutor : public clang::IncrementalExecutor {
     mutable unsigned RanCtors = false;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to