From: Heejin Ahn Date: Fri, 1 Jun 2018 01:01:37 +0000 (+0000) Subject: [WebAssembly] Hide new Wasm EH behind its feature flag X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=31db11052916d8a76e9a07d6039b0c0603879bba;p=clang [WebAssembly] Hide new Wasm EH behind its feature flag Summary: 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. Reviewers: dschuff Subscribers: sbc100, jgravelle-google, sunfish, cfe-commits Differential Revision: https://reviews.llvm.org/D47614 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333716 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index d38de34134..769b615cd4 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -154,7 +154,8 @@ static const EHPersonality &getObjCPersonality(const llvm::Triple &T, } 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) @@ -163,8 +164,10 @@ static const EHPersonality &getCXXPersonality(const llvm::Triple &T, 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; } @@ -172,12 +175,13 @@ static const EHPersonality &getCXXPersonality(const llvm::Triple &T, /// 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 EHPersonality &EHPersonality::get(CodeGenModule &CGM, 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 @@ void CodeGenModule::SimplifyPersonality() { const EHPersonality &ObjCXX = EHPersonality::get(*this, /*FD=*/nullptr); const EHPersonality &CXX = - getCXXPersonality(getTarget().getTriple(), LangOpts); + getCXXPersonality(getTarget().getTriple(), LangOpts, getTarget()); if (&ObjCXX == &CXX) return; diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 2a3564a4f5..3e2c461d6a 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -4102,7 +4102,8 @@ ItaniumCXXABI::LoadVTablePtr(CodeGenFunction &CGF, Address This, void WebAssemblyCXXABI::emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) { - CGF.EHStack.pushCleanup( - NormalCleanup, cast(CGF.CurrentFuncletPad)); + if (CGF.getTarget().hasFeature("exception-handling")) + CGF.EHStack.pushCleanup( + NormalCleanup, cast(CGF.CurrentFuncletPad)); ItaniumCXXABI::emitBeginCatch(CGF, C); } diff --git a/test/CodeGenCXX/wasm-eh.cpp b/test/CodeGenCXX/wasm-eh.cpp index 7fb4d38f0b..ea77fec820 100644 --- a/test/CodeGenCXX/wasm-eh.cpp +++ b/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;