https://github.com/vgvassilev created https://github.com/llvm/llvm-project/pull/175508
This patch avoids bloating the current folder with temporary files created by wasm and moves them in a separate tmp directory. This patch is a version of a downstream one resolving this issue. >From 0500e7260845f630b695324b26c392c8cafbe15f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev <[email protected]> Date: Mon, 12 Jan 2026 09:30:53 +0000 Subject: [PATCH] [clang-repl] Move the produced temporary files in wasm in a temp folder. This patch avoids bloating the current folder with temporary files created by wasm and moves them in a separate tmp directory. This patch is a version of a downstream one resolving this issue. --- clang/lib/Interpreter/IncrementalExecutor.cpp | 2 +- clang/lib/Interpreter/Wasm.cpp | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 001651522c329..74b751d0e2dae 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -404,7 +404,7 @@ IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC, llvm::Error Err = llvm::Error::success(); std::unique_ptr<IncrementalExecutor> Executor; #ifdef __EMSCRIPTEN__ - Executor = std::make_unique<WasmIncrementalExecutor>(); + Executor = std::make_unique<WasmIncrementalExecutor>(Err); #else Executor = std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err); #endif diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp index 56f51e5d5311e..68bfb871367da 100644 --- a/clang/lib/Interpreter/Wasm.cpp +++ b/clang/lib/Interpreter/Wasm.cpp @@ -57,7 +57,20 @@ bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, namespace clang { -WasmIncrementalExecutor::WasmIncrementalExecutor() = default; +WasmIncrementalExecutor::WasmIncrementalExecutor(llvm::Error &Err) { + llvm::ErrorAsOutParameter EAO(&Err); + + if (Err) + return; + + if (auto EC = + llvm::sys::fs::createUniqueDirectory("clang-wasm-exec-", TempDir)) + Err = llvm::make_error<llvm::StringError>( + "Failed to create temporary directory for Wasm executor: " + + EC.message(), + llvm::inconvertibleErrorCode()); +} + WasmIncrementalExecutor::~WasmIncrementalExecutor() = default; llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { @@ -74,11 +87,20 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { llvm::TargetMachine *TargetMachine = Target->createTargetMachine( PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); - std::string ObjectFileName = PTU.TheModule->getName().str() + ".o"; - std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm"; - std::error_code Error; - llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error); + llvm::SmallString<256> ObjectFileName(TempDir); + llvm::sys::path::append(ObjectFileName, + PTU.TheModule->getName() + ".o"); + + llvm::SmallString<256> BinaryFileName(TempDir); + llvm::sys::path::append(BinaryFileName, + PTU.TheModule->getName() + ".wasm"); + + std::error_code EC; + llvm::raw_fd_ostream ObjectFileOutput(ObjectFileName, EC); + + if (EC) + return llvm::errorCodeToError(EC); llvm::legacy::PassManager PM; if (TargetMachine->addPassesToEmitFile(PM, ObjectFileOutput, nullptr, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
