From 2a2e1563182c4ded9bb8baeb377a85bc84849549 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 22 Jan 2015 02:25:56 +0000 Subject: SEH: Emit the constant filter 1 as a catch-all Minor optimization of code like __try { ... } __except(1) { ... }. llvm-svn: 226766 --- clang/lib/CodeGen/CGException.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clang/lib/CodeGen/CGException.cpp') diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index 94cfca962d1..68764e92606 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1839,6 +1839,18 @@ void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt &S) { SEHExceptStmt *Except = S.getExceptHandler(); assert(Except); EHCatchScope *CatchScope = EHStack.pushCatch(1); + + // If the filter is known to evaluate to 1, then we can use the clause "catch + // i8* null". + llvm::Constant *C = + CGM.EmitConstantExpr(Except->getFilterExpr(), getContext().IntTy, this); + if (C && C->isOneValue()) { + CatchScope->setCatchAllHandler(0, createBasicBlock("__except")); + return; + } + + // In general, we have to emit an outlined filter function. Use the function + // in place of the RTTI typeinfo global that C++ EH uses. CodeGenFunction FilterCGF(CGM, /*suppressNewContext=*/true); llvm::Function *FilterFunc = FilterCGF.GenerateSEHFilterFunction(*this, *Except); -- cgit v1.2.3