mirror of https://github.com/rui314/chibicc.git
Make "main" to implicitly return 0
This commit is contained in:
parent
5257ee0f20
commit
9c36dd727c
|
@ -1284,6 +1284,13 @@ static void emit_text(Obj *prog) {
|
|||
gen_stmt(fn->body);
|
||||
assert(depth == 0);
|
||||
|
||||
// [https://www.sigbus.info/n1570#5.1.2.2.3p1] The C spec defines
|
||||
// a special rule for the main function. Reaching the end of the
|
||||
// main function is equivalent to returning 0, even though the
|
||||
// behavior is undefined for the other functions.
|
||||
if (strcmp(fn->name, "main") == 0)
|
||||
println(" mov $0, %%rax");
|
||||
|
||||
// Epilogue
|
||||
println(".L.return.%s:", fn->name);
|
||||
println(" mov %%rbp, %%rsp");
|
||||
|
|
|
@ -366,5 +366,4 @@ int main() {
|
|||
ASSERT(5, (***add2)(2,3));
|
||||
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue