Skip to content

Enable exceptions deployment #686

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ jobs:
elseif ( "${{ matrix.clang-runtime }}" -imatch "20" )
{
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
git apply -v emscripten-clang20-3-enable_exception_handling.patch
}
cd build
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
Expand Down
1 change: 1 addition & 0 deletions Emscripten-build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ On Windows execute the following
cd .\llvm-project\
cp -r ..\patches\llvm\emscripten-clang20*
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
git apply -v emscripten-clang20-3-enable_exception_handling.patch
```

We are now in a position to build an emscripten build of llvm by executing the following on Linux
Expand Down
1 change: 1 addition & 0 deletions docs/Emscripten-build-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ On Windows execute the following
cd .\llvm-project\
cp -r ..\patches\llvm\emscripten-clang20*
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
git apply -v emscripten-clang20-3-enable_exception_handling.patch

We are now in a position to build an emscripten build of llvm by executing the following on Linux
and osx
Expand Down
67 changes: 67 additions & 0 deletions patches/llvm/emscripten-clang20-3-enable_exception_handling.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 3b81f9d70..2704edb8a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -142,6 +142,48 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
return std::move(Clang);
}

+static llvm::Error HandleFrontendOptions(const CompilerInstance &CI) {
+ const auto &FrontendOpts = CI.getFrontendOpts();
+
+ if (FrontendOpts.ShowHelp) {
+ driver::getDriverOptTable().printHelp(
+ llvm::outs(), "clang -cc1 [options] file...",
+ "LLVM 'Clang' Compiler: http://clang.llvm.org",
+ /*ShowHidden=*/false, /*ShowAllAliases=*/false,
+ llvm::opt::Visibility(driver::options::CC1Option));
+ return llvm::createStringError(llvm::errc::not_supported, "Help displayed");
+ }
+
+ if (FrontendOpts.ShowVersion) {
+ llvm::cl::PrintVersionMessage();
+ return llvm::createStringError(llvm::errc::not_supported,
+ "Version displayed");
+ }
+
+ if (!FrontendOpts.LLVMArgs.empty()) {
+ unsigned NumArgs = FrontendOpts.LLVMArgs.size();
+ auto Args = std::make_unique<const char *[]>(NumArgs + 2);
+ Args[0] = "clang-repl (LLVM option parsing)";
+ for (unsigned i = 0; i != NumArgs; ++i) {
+ Args[i + 1] = FrontendOpts.LLVMArgs[i].c_str();
+ // remove the leading '-' from the option name
+ if (Args[i + 1][0] == '-') {
+ auto *option = static_cast<llvm::cl::opt<bool> *>(
+ llvm::cl::getRegisteredOptions()[Args[i + 1] + 1]);
+ if (option) {
+ option->setInitialValue(true);
+ } else {
+ llvm::errs() << "Unknown LLVM option: " << Args[i + 1] << "\n";
+ }
+ }
+ }
+ Args[NumArgs + 1] = nullptr;
+ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
+ }
+
+ return llvm::Error::success();
+}
+
} // anonymous namespace

namespace clang {
@@ -456,7 +498,12 @@ const char *const Runtimes = R"(

llvm::Expected<std::unique_ptr<Interpreter>>
Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
- llvm::Error Err = llvm::Error::success();
+
+ llvm::Error Err = HandleFrontendOptions(*CI);
+ if (Err) {
+ return std::move(Err);
+ }
+
auto Interp =
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
if (Err)
Loading