{"id":"9c9c876d44c84072","repo":"rust-lang/rust","slug":"llvm-does-not-have-support-for-cleanupret","errorCode":null,"errorMessage":"LLVM does not have support for cleanupret","messagePattern":"LLVM does not have support for cleanupret","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_llvm/src/builder.rs","lineNumber":1322,"sourceCode":"    }\n\n    fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> {\n        let ret = unsafe {\n            llvm::LLVMBuildCleanupPad(\n                self.llbuilder,\n                parent,\n                args.as_ptr(),\n                args.len() as c_uint,\n                c\"cleanuppad\".as_ptr(),\n            )\n        };\n        Funclet::new(ret.expect(\"LLVM does not have support for cleanuppad\"))\n    }\n\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,","sourceCodeStart":1304,"sourceCodeEnd":1340,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/builder.rs#L1304-L1340","documentation":"This panic is raised when `Builder::cleanup_ret` calls the LLVM-C `LLVMBuildCleanupRet` intrinsic (which emits a `cleanupret` instruction to exit a funclet cleanup pad during structured exception handling) and LLVM returns an error/null instead of a value. The `.expect(\"LLVM does not have support for cleanupret\")` guard converts the LLVM failure into an immediate compiler panic, since a missing cleanupret leaves the funclet IR malformed. It is the companion to cleanuppad for MSVC-style unwinding.","triggerScenarios":"Compulating any function that unwinds through a cleanup pad on an MSVC target (`*-pc-windows-msvc`) and the linked LLVM build does not support the `cleanupret` instruction — i.e. `LLVMBuildCleanupRet` at builder.rs:1321 returns Err. This typically happens only when the LLVM C API wrapper returns an error code for an unsupported EH opcode.","commonSituations":"Same root cause as the other funclet EH panics: a rustc built against an LLVM that lacks MSVC exception-handling support, a hand-built LLVM with `-DLLVM_ENABLE_EH=OFF`, or a toolchain mismatch where `rustc_codegen_llvm` is newer/older than its LLVM.","solutions":["Use the rustc toolchain's bundled LLVM instead of a system LLVM.","Rebuild LLVM with `-DLLVM_ENABLE_EH=ON` and `-DLLVM_ENABLE_MSVC`-compatible target support.","Upgrade or downgrade rustc to a release whose LLVM version matches the expected funclet EH support.","For non-shipping builds, compile with `-Cpanic=abort` to avoid emitting cleanupret."],"exampleFix":"// before\nRUSTFLAGS=\"-Cllvm-args=...\" rustc --target x86_64-pc-windows-msvc main.rs\n// after\nrustc +stable --target x86_64-pc-windows-msvc main.rs   # bundled LLVM","handlingStrategy":"validation","validationCode":"# cleanupret is the unwind edge emitted right after a cleanuppad, so the same\n# WinEH probe applies.\nrustc -vV >/dev/null 2>&1 || { echo 'no working rustc'; exit 1; }\nif [ -n \"$RUST_TARGET\" ] && case \"$RUST_TARGET\" in *windows-*) false;; *) true;; esac; then\n  echo \"target $RUST_TARGET will not emit funclet instructions\" \nelse\n  rustup show >/dev/null 2>&1 || echo 'WARNING: non-rustup toolchain; verify LLVM WinEH support'\nfi","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 cleanupret\"*)\n      echo \"LLVM cannot lower SEH cleanupret for this toolchain/target\" >&2\n      echo \"fix: use rustup toolchain or switch to *-windows-msvc\" >&2 ;;\n    *) echo \"$out\" >&2 ;;\n  esac\n  exit $rc\nfi","preventionTips":["Treat any panic mentioning 'cleanuppad'/'cleanupret' as a toolchain-LLVM incompatibility, not a source bug.","Keep the LLVM revision and rustc revision from the same rustup manifest; mixing them re-enables the path.","Document the required toolchain in rust-toolchain.toml so teammates and CI use a WinEH-capable LLVM.","Avoid the GNU Windows target for code that relies on unwinding across FFI boundaries unless you have verified SEH lowering."],"tags":["llvm","code-generation","windows","exception-handling","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}