[clang] [llvm] [WinEH] Fix try scopes leaking to caller on inline (PR #167176)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 17:46:10 PST 2025


================
@@ -635,14 +635,30 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
     ExitCXXTryStmt(S);
 }
 
+struct TerminateTryScope final : EHScopeStack::Cleanup {
+  llvm::BasicBlock *InvokeDest;
+
+  TerminateTryScope(llvm::BasicBlock *BB) : InvokeDest(BB) {}
+
+  void Emit(CodeGenFunction &CGF, Flags flags) override {
+    CGF.EmitSehTryScopeEnd(InvokeDest);
+  }
+};
+
+struct HandlerInfo {
+  CatchTypeInfo TypeInfo;
+  bool RequiresSehScope;
+};
+
 void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
   unsigned NumHandlers = S.getNumHandlers();
-  EHCatchScope *CatchScope = EHStack.pushCatch(NumHandlers);
+  unsigned NumHandlerInfos = NumHandlers > 0 ? NumHandlers - 1 : 0;
+  llvm::BasicBlock *DispatchBlock = nullptr;
+  llvm::SmallVector<HandlerInfo> HandlerInfos;
+  HandlerInfos.reserve(NumHandlerInfos);
----------------
efriedma-quic wrote:

It's not worth the extra code here to try to reserve the exact amount in the array.

https://github.com/llvm/llvm-project/pull/167176


More information about the llvm-commits mailing list