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) {