{"id":"858f9202ddafb677","repo":"rust-lang/rust","slug":"llvm-does-not-have-support-for-catchpad","errorCode":null,"errorMessage":"LLVM does not have support for catchpad","messagePattern":"LLVM does not have support for catchpad","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_llvm/src/builder.rs","lineNumber":1336,"sourceCode":"\n    fn cleanup_ret(&mut self, funclet: &Funclet<'ll>, unwind: Option<&'ll BasicBlock>) {\n        unsafe {\n            llvm::LLVMBuildCleanupRet(self.llbuilder, funclet.cleanuppad(), unwind)\n                .expect(\"LLVM does not have support for cleanupret\");\n        }\n    }\n\n    fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> {\n        let ret = unsafe {\n            llvm::LLVMBuildCatchPad(\n                self.llbuilder,\n                parent,\n                args.as_ptr(),\n                args.len() as c_uint,\n                c\"catchpad\".as_ptr(),\n            )\n        };\n        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\");","sourceCodeStart":1318,"sourceCodeEnd":1354,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/builder.rs#L1318-L1354","documentation":"This panic is emitted by `Builder::catch_pad` (builder.rs:1326-1336) when the LLVM-C call `LLVMBuildCatchPad` returns null, meaning the linked LLVM cannot emit a `catchpad` instruction. catchpad is part of Windows SEH funclet-based EH used to model `catch` blocks on MSVC targets; a null return indicates the LLVM backend lacks funclet EH. The `.expect(...)` guard turns the missing LLVM feature into a hard compiler abort.","triggerScenarios":"Lowering a Rust `catch`/try block (or any SEH catch construct) when targeting `*-pc-windows-msvc`, while the LLVM library that rustc was linked against does not implement the catchpad intrinsic. Fires inside `LLVMBuildCatchPad(...).expect(...)` once LLVM returns None.","commonSituations":"Custom rustc builds against a stripped-down LLVM; distro LLVM packages built without exception handling; mismatched `rustc_codegen_llvm` crate and LLVM version; cross-compiling to MSVC with a Linux-built LLVM lacking the X86 MSVC EH path.","solutions":["Install/use the rustc toolchain with its bundled LLVM.","Rebuild LLVM with EH and the X86 (MSVC) target enabled.","Pin rustc to a release known to ship a matching LLVM.","Avoid the MSVC target (use `*-pc-windows-gnu` or a non-Windows target) if you cannot fix LLVM."],"exampleFix":"// before\nrustc --target x86_64-pc-windows-msvc --sysroot=/opt/custom-llvm-sysroot\n// after\nrustc +stable --target x86_64-pc-windows-msvc   # toolchain's bundled LLVM","handlingStrategy":"validation","validationCode":"# catchpad only matters when catching C++/SEH exceptions via extern \"C\"/\n# extern \"C-unwind\". Gate such crates behind a target check.\ncase \"${RUST_TARGET:-$(rustc -vV | awk '/host:/ {print $2}')}\" in\n  *windows-msvc*|*windows-gnu*) rustup show active-toolchain >/dev/null 2>&1 \\\n      || echo 'custom toolchain: confirm LLVM has WinEH before building catch handlers' ;;\n  *) ;;\nesac","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 catchpad\"*)\n      echo \"LLVM lacks SEH catchpad lowering; rebuild with a WinEH-enabled LLVM\" >&2 ;;\n    *) echo \"$out\" >&2 ;;\n  esac\n  exit $rc\nfi","preventionTips":["When crossing the FFI boundary with C++ exceptions, target *-windows-msvc and a stock rustup LLVM.","Do not enable -Cpanic=unwind for SEH-catching code on a hand-built LLVM with WinEH disabled.","Reproduce the failure on the official toolchain first; if it disappears, the cause is the custom LLVM, not your code.","Track the rustc/LLVM version that introduced the personality you depend on, and pin it."],"tags":["llvm","code-generation","windows","exception-handling","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}