diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-05-08 16:19:46 -0700 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2020-05-19 01:16:09 -0700 |
commit | d94bacbcf87a06abc0c1fc3405406399460debc3 (patch) | |
tree | 11aabc6272b612a34e3d555ce2e40c3a896c51bf /clang/lib/CodeGen/CGException.cpp | |
parent | 51bb2128ef03985fddf2a84f17d3276f4ae2c6ad (diff) | |
download | llvm-d94bacbcf87a06abc0c1fc3405406399460debc3.zip llvm-d94bacbcf87a06abc0c1fc3405406399460debc3.tar.gz llvm-d94bacbcf87a06abc0c1fc3405406399460debc3.tar.bz2 |
[WebAssembly] Handle exception specifications
Summary:
Wasm currently does not fully handle exception specifications. Rather
than crashing,
- This treats `throw()` in the same way as `noexcept`.
- This ignores and prints a warning for `throw(type, ..)`, for a
temporary measure. This warning is controlled by
`-Wwasm-exception-spec`, which is on by default. You can suppress the
warning by using `-Wno-wasm-exception-spec`.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80061
Diffstat (limited to 'clang/lib/CodeGen/CGException.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGException.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index a5dae1b..d821eb2 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -20,6 +20,7 @@ #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtVisitor.h" +#include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/TargetBuiltins.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" @@ -468,6 +469,18 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) { // encode these in an object file but MSVC doesn't do anything with it. if (getTarget().getCXXABI().isMicrosoft()) return; + // In wasm we currently treat 'throw()' in the same way as 'noexcept'. In + // case of throw with types, we ignore it and print a warning for now. + // TODO Correctly handle exception specification in wasm + if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) { + if (EST == EST_DynamicNone) + EHStack.pushTerminate(); + else + CGM.getDiags().Report(D->getLocation(), + diag::warn_wasm_dynamic_exception_spec_ignored) + << FD->getExceptionSpecSourceRange(); + return; + } unsigned NumExceptions = Proto->getNumExceptions(); EHFilterScope *Filter = EHStack.pushFilter(NumExceptions); @@ -544,6 +557,14 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) { // encode these in an object file but MSVC doesn't do anything with it. if (getTarget().getCXXABI().isMicrosoft()) return; + // In wasm we currently treat 'throw()' in the same way as 'noexcept'. In + // case of throw with types, we ignore it and print a warning for now. + // TODO Correctly handle exception specification in wasm + if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) { + if (EST == EST_DynamicNone) + EHStack.popTerminate(); + return; + } EHFilterScope &filterScope = cast<EHFilterScope>(*EHStack.begin()); emitFilterDispatchBlock(*this, filterScope); EHStack.popFilter(); |