From c4565386553ea86308a9487650d2435804893ed0 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 15 Oct 2026 02:41:11 +0000 Subject: fix(codegen): restore runtime diagnostics before throwing Reuse historical runtime messages and source-line reporting for arithmetic, array, enum, pointer and file checks while preserving anonymous exceptions. Update the manuals and subsystem guidance to describe diagnostic output. Co-Authored-By: Claude Fable 5.1 --- include/cps/RuntimeCheck.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'include/cps/RuntimeCheck.h') diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h index d9a69b6..f5a8aa7 100644 --- a/include/cps/RuntimeCheck.h +++ b/include/cps/RuntimeCheck.h @@ -10,15 +10,24 @@ namespace cps { class ExceptionHandler; class RuntimeCheck { + llvm::Module &TheModule; llvm::LLVMContext &TheContext; llvm::IRBuilder<> &Builder; + + llvm::FunctionCallee PrintfFunc; ExceptionHandler &Exceptions; + llvm::Value *DivZeroMsg; + llvm::Value *OutOfBoundsMsg; + llvm::Value *EnumRangeMsg; + llvm::Value *NullDerefMsg; + llvm::Value *ArrayArgBoundsMsg; -public: - RuntimeCheck(llvm::LLVMContext &C, llvm::IRBuilder<> &B, ExceptionHandler &EH); + void setupExternalFunctions(); + void emitCheck(llvm::Value *Condition, llvm::Value *Msg, int Line); - // Split the block, throwing an anonymous exception when Condition is true. - void emitCheck(llvm::Value *Condition); +public: + RuntimeCheck(llvm::Module &M, llvm::LLVMContext &C, llvm::IRBuilder<> &B, + ExceptionHandler &EH); void emitDivZeroCheck(llvm::Value *Divisor, int Line); void emitIndexCheck(llvm::Value *Index, llvm::Value *Lower, llvm::Value *Upper, int Line); @@ -35,6 +44,13 @@ public: void emitArrayArgBoundsCheck(llvm::Value *ActualLower, llvm::Value *ActualUpper, int64_t DeclaredLower, int64_t DeclaredUpper, int Line); + // Print the diagnostic, then throw an anonymous exception on failure. + // Runtime-computed variant: FmtArgs are the printf varargs after Msg + // (e.g. {i32 line, ptr filename}). Needed when the failure site is inside + // a synthesized helper function, where the line number is an argument + // rather than a compile-time constant. + void emitCheck(llvm::Value *Condition, llvm::Value *Msg, + llvm::ArrayRef FmtArgs); }; } -- cgit v1.3.1-4-g156e