[PATCH] D79655: [WebAssembly] Ignore exception specifications

Heejin Ahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 8 16:41:10 PDT 2020


aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.

Wasm does not currently handle exception specifications such as
`throw()` or `throw(int)`. We have a plan to correctly implement this
later, but for usability at the moment, we simplify ignore them for a
temporary measure. A warning message will be printed. You can use
`noexcept` as a substitute for `throw()` from C++11.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79655

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGException.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/wasm-eh.cpp


Index: clang/test/CodeGenCXX/wasm-eh.cpp
===================================================================
--- clang/test/CodeGenCXX/wasm-eh.cpp
+++ clang/test/CodeGenCXX/wasm-eh.cpp
@@ -1,7 +1,6 @@
 // REQUIRES: webassembly-registered-target
 // RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 // RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
 
 void may_throw();
 void dont_throw() noexcept;
@@ -385,9 +384,20 @@
 
 // CHECK:   unreachable
 
+// Wasm ignores exception specifications at the moment. Checks if a warning
+// message is printed.
+void test9() throw() {
+}
+
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING
+
+// WARNING: warning: exception specifications are currently ignored in wasm
+
 // Here we only check if the command enables wasm exception handling in the
 // backend so that exception handling instructions can be generated in .s file.
 
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -S -o - -std=c++11 | FileCheck %s --check-prefix=ASSEMBLY
+
 // ASSEMBLY: try
 // ASSEMBLY: catch
 // ASSEMBLY: rethrow
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -17537,6 +17537,7 @@
              ArrayRef<ParsedType> DynamicExceptions,
              ArrayRef<SourceRange> DynamicExceptionRanges,
              Expr *NoexceptExpr) {
+  Diag(SpecificationRange.getBegin(), diag::warn_wasm_exception_spec_ignored);
   if (!MethodD)
     return;
 
Index: clang/lib/CodeGen/CGException.cpp
===================================================================
--- clang/lib/CodeGen/CGException.cpp
+++ 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,12 @@
     // encode these in an object file but MSVC doesn't do anything with it.
     if (getTarget().getCXXABI().isMicrosoft())
       return;
+    // TODO Correctly handle exception specification in wasm
+    if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
+      CGM.getDiags().Report(D->getLocation(),
+                            diag::warn_wasm_exception_spec_ignored);
+      return;
+    }
     unsigned NumExceptions = Proto->getNumExceptions();
     EHFilterScope *Filter = EHStack.pushFilter(NumExceptions);
 
@@ -544,6 +551,9 @@
     // encode these in an object file but MSVC doesn't do anything with it.
     if (getTarget().getCXXABI().isMicrosoft())
       return;
+    // TODO Correctly handle exception specification in wasm
+    if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly)
+      return;
     EHFilterScope &filterScope = cast<EHFilterScope>(*EHStack.begin());
     emitFilterDispatchBlock(*this, filterScope);
     EHStack.popFilter();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1590,6 +1590,8 @@
   "exception specification of %0 uses itself">;
 def err_exception_spec_incomplete_type : Error<
   "exception specification needed for member of incomplete class %0">;
+def warn_wasm_exception_spec_ignored : Warning<
+  "exception specifications are currently ignored in wasm">;
 
 // C++ access checking
 def err_class_redeclared_with_different_access : Error<


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79655.262976.patch
Type: text/x-patch
Size: 4345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200508/88fb0f5e/attachment-0001.bin>


More information about the cfe-commits mailing list