From 86e43a568dd932e04b17bb4ef369ef0d7ace515b Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Mon, 1 Jun 2026 11:11:43 +0200 Subject: [PATCH] fix switch int on x86 --- src/astgen.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/astgen.cpp b/src/astgen.cpp index 6bfd9c7..bac9236 100644 --- a/src/astgen.cpp +++ b/src/astgen.cpp @@ -15,6 +15,7 @@ #include "mangling.h" #include "target.h" +#include #include #include #include @@ -3444,6 +3445,16 @@ static JirRef astgenMatch(AstGenCtx &gctx, const AstNode &n, TypeIdx expected) { break; } } + // LLVM's SwitchInst requires unique case values; passing duplicates + // trips an assert in some builds and throws std::bad_alloc from + // SwitchLowering::buildJumpTable in LLVM 22 release builds. First- + // match-wins semantics: if value V appears in arm A and arm B (A seen; + switchCases.erase( + std::remove_if(switchCases.begin(), switchCases.end(), + [&](const SwitchCase &c) { return !seen.insert(c.value).second; }), + switchCases.end()); } if (tryingSwitch) { -- 2.51.2