From 98ef8bc4dfcebe44eece933ff0affc776b7199dd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 15:12:43 +0000 Subject: fix(codegen): raise a runtime error when a FUNCTION ends without RETURN Report the function and its header line, then throw, instead of silently returning zero. FUNCTION MAIN keeps its implicit result. Co-Authored-By: Claude Sonnet 5.5 --- include/cps/FunctionGen.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index 6c5c7c0..f5e5ba2 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -86,6 +86,7 @@ private: std::function BeforeCall; ArrayParamBinder BindArrayParam; std::function RegisterCopy; + std::function MissingReturn; ClangABI ABI{Context, Types}; // clang context created on the first EXTERN void createArgumentAllocas(llvm::Function *F, const std::vector &Params, bool IsMethod); @@ -105,6 +106,12 @@ public: void setArrayParamBinder(ArrayParamBinder Binder) { BindArrayParam = std::move(Binder); } + // Called (with the FUNCTION header line and name) where a non-VOID FUNCTION + // body can fall off its end; emits the runtime error and throw. + void setMissingReturnHandler(std::function Handler) { + MissingReturn = std::move(Handler); + } + void setCopyRegistrar(std::function Registrar) { RegisterCopy = std::move(Registrar); } -- cgit v1.3.1-4-g156e