[PATCH] D47614: [WebAssembly] Hide new Wasm EH behind its feature flag

Heejin Ahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 31 17:48:57 PDT 2018


aheejin created this revision.
aheejin added reviewers: dschuff, majnemer.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.

clang's current wasm EH implementation is a non-MVP feature in progress.
We had a `-mexception-handling` wasm feature but were not using it. This
patch hides the non-MVP wasm EH behind a flag, so it does not affect
other code for now.


Repository:
  rC Clang

https://reviews.llvm.org/D47614

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGenCXX/wasm-eh.cpp


Index: test/CodeGenCXX/wasm-eh.cpp
===================================================================
--- test/CodeGenCXX/wasm-eh.cpp
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
-// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-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 -target-feature +exception-handling -emit-llvm -o - -std=c++11 | FileCheck %s
 
 void may_throw();
 void dont_throw() noexcept;
Index: lib/CodeGen/CGException.cpp
===================================================================
--- lib/CodeGen/CGException.cpp
+++ lib/CodeGen/CGException.cpp
@@ -154,30 +154,34 @@
 }
 
 static const EHPersonality &getCXXPersonality(const llvm::Triple &T,
-                                              const LangOptions &L) {
+                                              const LangOptions &L,
+                                              const TargetInfo &Target) {
   if (L.SjLjExceptions)
     return EHPersonality::GNU_CPlusPlus_SJLJ;
   if (L.DWARFExceptions)
     return EHPersonality::GNU_CPlusPlus;
   if (T.isWindowsMSVCEnvironment())
     return EHPersonality::MSVC_CxxFrameHandler3;
   if (L.SEHExceptions)
     return EHPersonality::GNU_CPlusPlus_SEH;
-  if (T.getArch() == llvm::Triple::wasm32 ||
-      T.getArch() == llvm::Triple::wasm64)
+  // Wasm EH is a non-MVP feature for now.
+  if (Target.hasFeature("exception-handling") &&
+      (T.getArch() == llvm::Triple::wasm32 ||
+       T.getArch() == llvm::Triple::wasm64))
     return EHPersonality::GNU_Wasm_CPlusPlus;
   return EHPersonality::GNU_CPlusPlus;
 }
 
 /// Determines the personality function to use when both C++
 /// and Objective-C exceptions are being caught.
 static const EHPersonality &getObjCXXPersonality(const llvm::Triple &T,
-                                                 const LangOptions &L) {
+                                                 const LangOptions &L,
+                                                 const TargetInfo &Target) {
   switch (L.ObjCRuntime.getKind()) {
   // In the fragile ABI, just use C++ exception handling and hope
   // they're not doing crazy exception mixing.
   case ObjCRuntime::FragileMacOSX:
-    return getCXXPersonality(T, L);
+    return getCXXPersonality(T, L, Target);
 
   // The ObjC personality defers to the C++ personality for non-ObjC
   // handlers.  Unlike the C++ case, we use the same personality
@@ -209,14 +213,16 @@
                                         const FunctionDecl *FD) {
   const llvm::Triple &T = CGM.getTarget().getTriple();
   const LangOptions &L = CGM.getLangOpts();
+  const TargetInfo &Target = CGM.getTarget();
 
   // Functions using SEH get an SEH personality.
   if (FD && FD->usesSEHTry())
     return getSEHPersonalityMSVC(T);
 
   if (L.ObjC1)
-    return L.CPlusPlus ? getObjCXXPersonality(T, L) : getObjCPersonality(T, L);
-  return L.CPlusPlus ? getCXXPersonality(T, L) : getCPersonality(T, L);
+    return L.CPlusPlus ? getObjCXXPersonality(T, L, Target)
+                       : getObjCPersonality(T, L);
+  return L.CPlusPlus ? getCXXPersonality(T, L, Target) : getCPersonality(T, L);
 }
 
 const EHPersonality &EHPersonality::get(CodeGenFunction &CGF) {
@@ -313,7 +319,7 @@
 
   const EHPersonality &ObjCXX = EHPersonality::get(*this, /*FD=*/nullptr);
   const EHPersonality &CXX =
-      getCXXPersonality(getTarget().getTriple(), LangOpts);
+      getCXXPersonality(getTarget().getTriple(), LangOpts, getTarget());
   if (&ObjCXX == &CXX)
     return;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47614.149385.patch
Type: text/x-patch
Size: 3932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180601/797207d3/attachment-0001.bin>


More information about the cfe-commits mailing list