diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 15:12:43 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 15:21:11 +0000 |
| commit | 98ef8bc4dfcebe44eece933ff0affc776b7199dd (patch) | |
| tree | d02ffca5fd65852344a3e032bfbd3a4638c79dac /lib/CodeGen/FunctionGen.cc | |
| parent | 8b6ba7222d9990bc19e355eabcf046a7ea773545 (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 'lib/CodeGen/FunctionGen.cc')
| -rw-r--r-- | lib/CodeGen/FunctionGen.cc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index 48c9978..c233205 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -444,6 +444,10 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, if (!Builder.GetInsertBlock()->hasTerminator()) { if (sameIdentifier(Proto->getReturnType(), "VOID")) { Exceptions.recordExit(Builder.CreateRetVoid()); + } else if (MissingReturn && !(!IsMethod && sameIdentifier(Proto->getName(), "MAIN"))) { + // Falling off the end of a FUNCTION is a runtime error, not a zero value. + // The handler ends the block with a throw (unreachable). + MissingReturn(FuncAST->getLine(), Proto->getName()); } else { Exceptions.recordExit(Builder.CreateRet(Constant::getNullValue(TheFunction->getReturnType()))); } |
