https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/175910
>From 7edf2a3e11ed210f65fbc3e516eb227b6b7dd233 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 | 2 ++ clang/include/clang/Interpreter/Interpreter.h | 2 -- clang/lib/Interpreter/CMakeLists.txt | 29 ++++++++++-------- clang/lib/Interpreter/IncrementalExecutor.cpp | 11 ++----- clang/lib/Interpreter/Interpreter.cpp | 3 +- clang/lib/Interpreter/Wasm.cpp | 30 +++++++++++++++++++ clang/unittests/Interpreter/CMakeLists.txt | 12 ++++---- .../Interpreter/InterpreterExtensionsTest.cpp | 3 ++ 8 files changed, 60 insertions(+), 32 deletions(-) diff --git a/clang/include/clang/Interpreter/IncrementalExecutor.h b/clang/include/clang/Interpreter/IncrementalExecutor.h index 913da9230a947..90f858ff90b15 100644 --- a/clang/include/clang/Interpreter/IncrementalExecutor.h +++ b/clang/include/clang/Interpreter/IncrementalExecutor.h @@ -52,8 +52,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 c2622b23d5d9c..0dd1e52749b4f 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 01d3295d1ac30..95bac67e1b9db 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 5d01ba4774269..db805bb4219a4 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" @@ -427,12 +424,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 40fbc83db9107..48ed3f614a50b 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -45,9 +45,8 @@ #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 573c8910d3a41..7739747ca69be 100644 --- a/clang/lib/Interpreter/Wasm.cpp +++ b/clang/lib/Interpreter/Wasm.cpp @@ -61,6 +61,36 @@ bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, namespace clang { +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 6d999104054c3..466563e5c4a24 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 @@ -71,10 +71,10 @@ if(TARGET compiler-rt AND LLVM_ON_UNIX) endif() if(EMSCRIPTEN) -# Without the above you try to link to LLVMSupport twice, and end -# up with a duplicate symbol error when creating the main module +# LLVMSupport and llvm_gtest are linked transitively. Repeated archives cause +# duplicate symbol errors when creating the main module. get_target_property(LINKED_LIBS ClangReplInterpreterTests LINK_LIBRARIES) -list(REMOVE_ITEM LINKED_LIBS LLVMSupport) +list(REMOVE_ITEM LINKED_LIBS LLVMSupport llvm_gtest default_gtest) set_target_properties(ClangReplInterpreterTests PROPERTIES LINK_LIBRARIES "${LINKED_LIBS}") target_link_options(ClangReplInterpreterTests PUBLIC "SHELL: -s MAIN_MODULE=1" @@ -93,8 +93,8 @@ set_target_properties(ClangReplInterpreterTests PROPERTIES ) endif() -# Exceptions on Windows are not yet supported. -if(NOT WIN32) +# Interpreter exception tests are not supported on Windows or Emscripten. +if(NOT WIN32 AND NOT EMSCRIPTEN) add_subdirectory(ExceptionTests) endif() diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp index 13825f2cbdddf..642869e124b8b 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
