aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 15:12:43 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 15:21:11 +0000
commit98ef8bc4dfcebe44eece933ff0affc776b7199dd (patch)
treed02ffca5fd65852344a3e032bfbd3a4638c79dac /include
parent8b6ba7222d9990bc19e355eabcf046a7ea773545 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'include')
-rw-r--r--include/cps/FunctionGen.h7
1 files changed, 7 insertions, 0 deletions
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<void(const FuncSig &)> BeforeCall;
ArrayParamBinder BindArrayParam;
std::function<void(llvm::Value *, const std::string &, int)> RegisterCopy;
+ std::function<void(int, const std::string &)> MissingReturn;
ClangABI ABI{Context, Types}; // clang context created on the first EXTERN
void createArgumentAllocas(llvm::Function *F, const std::vector<ParamDecl> &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<void(int, const std::string &)> Handler) {
+ MissingReturn = std::move(Handler);
+ }
+
void setCopyRegistrar(std::function<void(llvm::Value *, const std::string &, int)> Registrar) {
RegisterCopy = std::move(Registrar);
}