https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/86815
None >From 290827f07c63fa59f816b048f425d90b02a7afbe 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index f87caf050eeaa7..c2120d1b844c6e 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -904,19 +904,24 @@ 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); + llvm::SwitchInst::Create(Load, Default, SwitchCapacity); InstsToAppend.push_back(Load); InstsToAppend.push_back(Switch); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits