llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Vassil Vassilev (vgvassilev) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/175508.diff 2 Files Affected: - (modified) clang/lib/Interpreter/IncrementalExecutor.cpp (+1-1) - (modified) clang/lib/Interpreter/Wasm.cpp (+27-5) ``````````diff 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, `````````` </details> https://github.com/llvm/llvm-project/pull/175508 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
