{"id":"38559ec5f830f407","repo":"rust-lang/rust","slug":"llvm-does-not-have-support-for-catchswitch","errorCode":null,"errorMessage":"LLVM does not have support for catchswitch","messagePattern":"LLVM does not have support for catchswitch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_llvm/src/builder.rs","lineNumber":1354,"sourceCode":"        Funclet::new(ret.expect(\"LLVM does not have support for catchpad\"))\n    }\n\n    fn catch_switch(\n        &mut self,\n        parent: Option<&'ll Value>,\n        unwind: Option<&'ll BasicBlock>,\n        handlers: &[&'ll BasicBlock],\n    ) -> &'ll Value {\n        let ret = unsafe {\n            llvm::LLVMBuildCatchSwitch(\n                self.llbuilder,\n                parent,\n                unwind,\n                handlers.len() as c_uint,\n                c\"catchswitch\".as_ptr(),\n            )\n        };\n        let ret = ret.expect(\"LLVM does not have support for catchswitch\");\n        for handler in handlers {\n            unsafe {\n                llvm::LLVMAddHandler(ret, handler);\n            }\n        }\n        ret\n    }\n\n    fn get_funclet_cleanuppad(&self, funclet: &Funclet<'ll>) -> &'ll Value {\n        funclet.cleanuppad()\n    }\n\n    // Atomic Operations\n    fn atomic_cmpxchg(\n        &mut self,\n        dst: &'ll Value,\n        cmp: &'ll Value,\n        src: &'ll Value,","sourceCodeStart":1336,"sourceCodeEnd":1372,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/builder.rs#L1336-L1372","documentation":"This panic is raised by `Builder::catch_switch` (builder.rs:1339-1354) when the LLVM-C API `LLVMBuildCatchSwitch` returns null. The catchswitch instruction is the root of a Windows SEH catch handler within a funclet; if LLVM cannot build one, codegen cannot proceed and `.expect(\"LLVM does not have support for catchswitch\")` aborts the compiler. Like the other funclet EH panics it signals that the linked LLVM lacks MSVC exception-handling support.","triggerScenarios":"Compiling unwinding code that needs a catch handler dispatch on an MSVC target (`x86_64-pc-windows-msvc`/`i686-pc-windows-msvc`) and LLVM's `LLVMBuildCatchSwitch` returns None. The panic happens at builder.rs:1354 right after the FFI call, before any handlers can be added via `LLVMAddHandler`.","commonSituations":"Toolchain with a system/custom LLVM missing EH; rustc built without the matching LLVM commit; cross-compile to MSVC from a host LLVM that lacks MSVC EH support.","solutions":["Use rustc's bundled LLVM (default toolchain).","Rebuild LLVM with exception handling and the MSVC-capable X86 backend.","Match rustc and LLVM versions exactly (rebuild rustc via `./x.py build`).","Switch panic strategy (`-Cpanic=abort`) or use a non-MSVC target to sidestep catchswitch emission."],"exampleFix":"// before\nRUSTFLAGS=\"-Clinker=lld-link\" rustc --target x86_64-pc-windows-msvc app.rs\n// after\nrustc +stable --target x86_64-pc-windows-msvc app.rs","handlingStrategy":"validation","validationCode":"# catchswitch is the root of an SEH catch dispatch. Same trigger class as\n# 170-172; reuse the toolchain-integrity probe.\nrustc --version --verbose | grep -E '^release:' >/dev/null || { echo 'unidentified toolchain'; exit 1; }\nrustc --print=sysroot >/dev/null 2>&1 || { echo 'broken sysroot'; exit 1; }","typeGuard":null,"tryCatchPattern":"out=\"$(cargo build 2>&1)\"; rc=$?\nif [ $rc -ne 0 ]; then\n  case \"$out\" in\n    *\"LLVM does not have support for catchswitch\"*)\n      echo \"SEH catchswitch unsupported by this LLVM; switch toolchain or target\" >&2 ;;\n    *) echo \"$out\" >&2 ;;\n  esac\n  exit $rc\nfi","preventionTips":["Pin a known-good toolchain with rust-toolchain.toml.","Audit any sysroot/RUSTFLAGS that override --llvm-path or point at a custom libLLVM.","Run `rustup component add rust-src` only against matching toolchains to avoid drift.","If you maintain a custom rustc, configure LLVM with EH and WinEH backends enabled."],"tags":["llvm","code-generation","windows","exception-handling","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}