-
Notifications
You must be signed in to change notification settings - Fork 15.8k
[clang-repl] Move the produced temporary files in wasm in a temp folder. #175508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@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. |
|
Ahh getting this error while building. Pasted the exact diff as provided. Debugging the above now ! |
|
This diff should be enough |
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
anutosh491
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…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 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.