From 2362e6648b5126c39d1692c145836d4d8883ac66 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:53:11 +0000 Subject: [PATCH] refactor: replace LLVM unreachable with explicit compiler error for Throw terminator The LLVM backend was previously generating an `unreachable` LLVM instruction for the `Throw` IR terminator, as full exception handling is not yet implemented. This led to unsafe execution and undefined behavior if triggered. This change modifies `codegen.rs` to return a clear Rust `Err` during compile time if an exception construct is encountered, causing compilation to gracefully fail instead of producing a potentially dangerous and undefined binary. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- compiler/llvm_backend/src/codegen.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/llvm_backend/src/codegen.rs b/compiler/llvm_backend/src/codegen.rs index 769ce51e..90fd5916 100644 --- a/compiler/llvm_backend/src/codegen.rs +++ b/compiler/llvm_backend/src/codegen.rs @@ -125,8 +125,7 @@ impl<'a> CodegenEngine<'a> { LLVMBuildBr(self.ctx.builder, dest_block); } TerminatorKind::Throw(_) => { - // TODO: Implement exception handling or unwind - LLVMBuildUnreachable(self.ctx.builder); + return Err("Exception handling (throw) is not yet implemented in the LLVM backend".to_string()); } TerminatorKind::ConditionalJump { cond,