https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/86815
>From 43a81cbf959fc47ffbabb1741d16a790fc4694aa Mon Sep 17 00:00:00 2001 From: Rose <gfunni...@gmail.com> Date: Wed, 27 Mar 2024 11:21:18 -0400 Subject: [PATCH] [clang] Compute Switch Capacity based on number of branch-afters and fixups --- clang/lib/CodeGen/CGCleanup.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index f87caf050eeaa7..762dddb5e0f910 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -904,17 +904,22 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { (HasFixups && !HasEnclosingCleanups)) { llvm::BasicBlock *Default = - (BranchThroughDest ? BranchThroughDest : getUnreachableBlock()); - - // TODO: base this on the number of branch-afters and fixups - const unsigned SwitchCapacity = 10; + (BranchThroughDest ? BranchThroughDest : getUnreachableBlock()); // pass the abnormal exit flag to Fn (SEH cleanup) cleanupFlags.setHasExitSwitch(); - llvm::LoadInst *Load = - createLoadInstBefore(getNormalCleanupDestSlot(), "cleanup.dest", - nullptr); + llvm::LoadInst *Load = createLoadInstBefore(getNormalCleanupDestSlot(), + "cleanup.dest", nullptr); + + unsigned numBranchAfters = Scope.getNumBranchAfters(); + unsigned numFixups = (HasFixups && !HasEnclosingCleanups) + ? EHStack.getNumBranchFixups() - FixupDepth + : 0; + + // Compute Switch Capacity based on number of branch-afters and fixups. + const unsigned SwitchCapacity = numBranchAfters + numFixups; + llvm::SwitchInst *Switch = llvm::SwitchInst::Create(Load, Default, SwitchCapacity); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits