codegen: void main() should exit 0, not leak a garbage exit code#3
Merged
Conversation
…leaking a garbage exit code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
fn main()with no return type (a void main) was compiled todefine void @main(...). Butmainis the process entry point — the OS reads its return register as the exit code. Avoidfunction leaves garbage in that register, so a program that should succeed exited nonzero (consistently 10 in testing), e.g.:This is why fixtures had to end in a string print or use
fn main(): i32 { ... return 0 }to pass — an int-ending void main failed the harness's exit-code check. Surfaced while adding the compound-bitwise fixture.Fix
In
genFn, force@mainto bei32-returning regardless of the Milo signature, and make a barereturninside main emitret i32 0(so it matches the forced signature). The existing fallthrough already emitsret i32 0once the return type isi32. Explicitreturn <n>exit codes are preserved.Tests
tests/fixtures/voidMainExit.milo— void main ending inprint(<int>), must exit 0.fn main(): i32 { return 5 }still exits 5; full suite 349 pass / 0 fail.