https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/216132
>From 715b0c4ecf1a67389f6fcb7179d6f85f0e345311 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Thu, 13 Aug 2026 18:26:54 +0200 Subject: [PATCH 1/3] lli: Record the host triple on triple-less modules The JIT compiles for the host, but modules without a target triple kept an empty triple, which module-triple-based analyses (e.g. runtime libcall selection) cannot resolve. Set the resolved JIT triple on the module. This defends against jit test regressions when RuntimeLibraryInfo starts getting computed from the module instead of TargetOptions. Co-authored-by: Claude (Claude-Opus-4.8) <[email protected]> --- llvm/tools/lli/lli.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index cbc85d6272010..5f3eece50ad09 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -516,7 +516,12 @@ int main(int argc, char **argv, char * const *envp) { builder.setTargetOptions(Options); - std::unique_ptr<ExecutionEngine> EE(builder.create()); + // Resolve the target the JIT will compile for and record it in the module + TargetMachine *TM = builder.selectTarget(); + if (TM && Mod->getTargetTriple().empty()) + Mod->setTargetTriple(TM->getTargetTriple()); + + std::unique_ptr<ExecutionEngine> EE(builder.create(TM)); if (!EE) { if (!ErrorMsg.empty()) WithColor::error(errs(), argv[0]) @@ -946,6 +951,14 @@ static int runOrcJIT(const char *ProgName) { Builder.getJITTargetMachineBuilder()->getTargetTriple().setArchName( codegen::getMArch()); + // Record the triple the JIT compiles for on triple-less modules. + const Triple &JITTriple = + Builder.getJITTargetMachineBuilder()->getTargetTriple(); + MainModule.withModuleDo([&](Module &M) { + if (M.getTargetTriple().empty()) + M.setTargetTriple(JITTriple); + }); + Builder.getJITTargetMachineBuilder() ->setCPU(codegen::getCPUStr()) .addFeatures(codegen::getFeatureList()) >From 2b2b8b1c86a4be3a7241721b38efae7947623f88 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Fri, 14 Aug 2026 09:53:17 +0200 Subject: [PATCH 2/3] Move to LLJIT and add error test --- .../Interpreter/InterpreterExtensionsTest.cpp | 2 +- llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h | 2 +- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 17 ++++-- llvm/tools/lli/lli.cpp | 8 --- .../ExecutionEngine/Orc/CMakeLists.txt | 1 + .../ExecutionEngine/Orc/LLJITTest.cpp | 52 +++++++++++++++++++ 6 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp index 13825f2cbdddf..c985701ce911e 100644 --- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp +++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp @@ -99,7 +99,7 @@ TEST_F(InterpreterExtensionsTest, CustomCrossJIT) { if (!IsARMTargetRegistered()) GTEST_SKIP(); - std::string TargetTriple = "armv6-none-eabi"; + std::string TargetTriple = "armv6-unknown-none-eabi"; IncrementalCompilerBuilder CB; CB.SetTargetTriple(TargetTriple); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h index 62fe44d6bcba7..7f391863985ce 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -261,7 +261,7 @@ class LLVM_ABI LLJIT { /// Create an LLJIT instance with a single compile thread. LLJIT(LLJITBuilderState &S, Error &Err); - Error applyDataLayout(Module &M); + Error applyTargetConfig(Module &M); std::unique_ptr<ExecutionSession> ES; std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr; diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 21e2c5ed41a83..ad02be5e3928d 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -912,7 +912,7 @@ Error LLJIT::addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM) { assert(TSM && "Can not add null module"); if (auto Err = - TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); })) + TSM.withModuleDo([&](Module &M) { return applyTargetConfig(M); })) return Err; return InitHelperTransformLayer->add(std::move(RT), std::move(TSM)); @@ -1107,13 +1107,22 @@ std::string LLJIT::mangle(StringRef UnmangledName) const { return MangledName; } -Error LLJIT::applyDataLayout(Module &M) { +Error LLJIT::applyTargetConfig(Module &M) { + if (M.getTargetTriple().empty()) { + M.setTargetTriple(TT); + } else if (!M.getTargetTriple().isCompatibleWith(TT)) { + return make_error<StringError>("added module has an incompatible triple: " + + M.getTargetTriple().str() + + " (module) vs " + TT.str() + " (jit)", + inconvertibleErrorCode()); + } + if (M.getDataLayout().isDefault()) M.setDataLayout(DL); if (M.getDataLayout() != DL) return make_error<StringError>( - "Added modules have incompatible data layouts: " + + "added module has an incompatible data layout: " + M.getDataLayout().getStringRepresentation() + " (module) vs " + DL.getStringRepresentation() + " (jit)", inconvertibleErrorCode()); @@ -1306,7 +1315,7 @@ Error LLLazyJIT::addLazyIRModule(JITDylib &JD, ThreadSafeModule TSM) { assert(TSM && "Can not add null module"); if (auto Err = TSM.withModuleDo( - [&](Module &M) -> Error { return applyDataLayout(M); })) + [&](Module &M) -> Error { return applyTargetConfig(M); })) return Err; return CODLayer->add(JD, std::move(TSM)); diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 5f3eece50ad09..97d2e7191e9b0 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -951,14 +951,6 @@ static int runOrcJIT(const char *ProgName) { Builder.getJITTargetMachineBuilder()->getTargetTriple().setArchName( codegen::getMArch()); - // Record the triple the JIT compiles for on triple-less modules. - const Triple &JITTriple = - Builder.getJITTargetMachineBuilder()->getTargetTriple(); - MainModule.withModuleDo([&](Module &M) { - if (M.getTargetTriple().empty()) - M.setTargetTriple(JITTriple); - }); - Builder.getJITTargetMachineBuilder() ->setCPU(codegen::getCPUStr()) .addFeatures(codegen::getFeatureList()) diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt index 5dc798c64eea9..f5ce670b87157 100644 --- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt +++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt @@ -28,6 +28,7 @@ add_llvm_unittest(OrcJITTests IndirectionUtilsTest.cpp InProcessEPCTest.cpp JITTargetMachineBuilderTest.cpp + LLJITTest.cpp LazyCallThroughAndReexportsTest.cpp LibraryResolverTest.cpp LinkGraphLinkingLayerTest.cpp diff --git a/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp b/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp new file mode 100644 index 0000000000000..e8fcd608da755 --- /dev/null +++ b/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp @@ -0,0 +1,52 @@ +//===----------- LLJITTest.cpp - Unit tests for LLJIT ---------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "OrcTestCommon.h" +#include "llvm/IR/Module.h" +#include "llvm/Testing/Support/Error.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::orc; + +namespace { + +TEST(LLJITTest, AddModuleWithIncompatibleTripleErrors) { + OrcNativeTarget::initialize(); + + auto J = LLJITBuilder().create(); + if (!J) { + consumeError(J.takeError()); + GTEST_SKIP(); + } + + // Build a module whose triple differs from the JIT's by OS, which makes it + // incompatible with the JIT target. Pick any OS other than the host's. + Triple ModuleTriple = (*J)->getTargetTriple(); + Triple::OSType IncompatibleOS = Triple::UnknownOS; + for (Triple::OSType OS : {Triple::Linux, Triple::Win32, Triple::Darwin}) { + if (OS != ModuleTriple.getOS()) { + IncompatibleOS = OS; + break; + } + } + ASSERT_NE(IncompatibleOS, Triple::UnknownOS); + + ModuleTriple.setOS(IncompatibleOS); + + std::unique_ptr<LLVMContext> Ctx(new LLVMContext()); + std::unique_ptr<Module> M(new Module("M", *Ctx)); + M->setTargetTriple(ModuleTriple); + + EXPECT_THAT_ERROR( + (*J)->addIRModule(ThreadSafeModule(std::move(M), std::move(Ctx))), + FailedWithMessage(testing::HasSubstr("incompatible triple"))); +} + +} // namespace >From 3d0f99369832588f4099e8739a5b7d14bb087d88 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Fri, 14 Aug 2026 13:14:09 +0200 Subject: [PATCH 3/3] Remove incompatible triple error --- .../Interpreter/InterpreterExtensionsTest.cpp | 2 +- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 10 +--- .../ExecutionEngine/Orc/CMakeLists.txt | 1 - .../ExecutionEngine/Orc/LLJITTest.cpp | 52 ------------------- 4 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp index c985701ce911e..13825f2cbdddf 100644 --- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp +++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp @@ -99,7 +99,7 @@ TEST_F(InterpreterExtensionsTest, CustomCrossJIT) { if (!IsARMTargetRegistered()) GTEST_SKIP(); - std::string TargetTriple = "armv6-unknown-none-eabi"; + std::string TargetTriple = "armv6-none-eabi"; IncrementalCompilerBuilder CB; CB.SetTargetTriple(TargetTriple); diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index ad02be5e3928d..f34a6544ada56 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -1108,21 +1108,15 @@ std::string LLJIT::mangle(StringRef UnmangledName) const { } Error LLJIT::applyTargetConfig(Module &M) { - if (M.getTargetTriple().empty()) { + if (M.getTargetTriple().empty()) M.setTargetTriple(TT); - } else if (!M.getTargetTriple().isCompatibleWith(TT)) { - return make_error<StringError>("added module has an incompatible triple: " + - M.getTargetTriple().str() + - " (module) vs " + TT.str() + " (jit)", - inconvertibleErrorCode()); - } if (M.getDataLayout().isDefault()) M.setDataLayout(DL); if (M.getDataLayout() != DL) return make_error<StringError>( - "added module has an incompatible data layout: " + + "Added modules have incompatible data layouts: " + M.getDataLayout().getStringRepresentation() + " (module) vs " + DL.getStringRepresentation() + " (jit)", inconvertibleErrorCode()); diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt index f5ce670b87157..5dc798c64eea9 100644 --- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt +++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt @@ -28,7 +28,6 @@ add_llvm_unittest(OrcJITTests IndirectionUtilsTest.cpp InProcessEPCTest.cpp JITTargetMachineBuilderTest.cpp - LLJITTest.cpp LazyCallThroughAndReexportsTest.cpp LibraryResolverTest.cpp LinkGraphLinkingLayerTest.cpp diff --git a/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp b/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp deleted file mode 100644 index e8fcd608da755..0000000000000 --- a/llvm/unittests/ExecutionEngine/Orc/LLJITTest.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------- LLJITTest.cpp - Unit tests for LLJIT ---------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/ExecutionEngine/Orc/LLJIT.h" -#include "OrcTestCommon.h" -#include "llvm/IR/Module.h" -#include "llvm/Testing/Support/Error.h" -#include "gtest/gtest.h" - -using namespace llvm; -using namespace llvm::orc; - -namespace { - -TEST(LLJITTest, AddModuleWithIncompatibleTripleErrors) { - OrcNativeTarget::initialize(); - - auto J = LLJITBuilder().create(); - if (!J) { - consumeError(J.takeError()); - GTEST_SKIP(); - } - - // Build a module whose triple differs from the JIT's by OS, which makes it - // incompatible with the JIT target. Pick any OS other than the host's. - Triple ModuleTriple = (*J)->getTargetTriple(); - Triple::OSType IncompatibleOS = Triple::UnknownOS; - for (Triple::OSType OS : {Triple::Linux, Triple::Win32, Triple::Darwin}) { - if (OS != ModuleTriple.getOS()) { - IncompatibleOS = OS; - break; - } - } - ASSERT_NE(IncompatibleOS, Triple::UnknownOS); - - ModuleTriple.setOS(IncompatibleOS); - - std::unique_ptr<LLVMContext> Ctx(new LLVMContext()); - std::unique_ptr<Module> M(new Module("M", *Ctx)); - M->setTargetTriple(ModuleTriple); - - EXPECT_THAT_ERROR( - (*J)->addIRModule(ThreadSafeModule(std::move(M), std::move(Ctx))), - FailedWithMessage(testing::HasSubstr("incompatible triple"))); -} - -} // namespace _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
