[clang-repl] Move the produced temporary files in wasm in a temp folder.#175508
Merged
Conversation
Member
|
@llvm/pr-subscribers-clang Author: Vassil Vassilev (vgvassilev) ChangesThis 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:
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,
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Member
|
Ahh getting this error while building. Pasted the exact diff as provided. Debugging the above now ! |
Member
|
This diff should be enough |
Member
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. Co-authored with Anutosh Bhat.
0500e72 to
6ae13f2
Compare
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Jan 18, 2026
…er. (llvm#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. Co-authored with Anutosh Bhat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.
Co-authored with Anutosh Bhat.