Adjust code to C99 regarding the main function: Not returning anything in a
main function with an int return type is identical to returning zero. git-svn-id: svn://svn.cc65.org/cc65/trunk@5118 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
2f75733e43
commit
d1efe1af90
2 changed files with 27 additions and 5 deletions
|
@ -369,6 +369,7 @@ static void F_RestoreRegVars (Function* F)
|
||||||
void NewFunc (SymEntry* Func)
|
void NewFunc (SymEntry* Func)
|
||||||
/* Parse argument declarations and function body. */
|
/* Parse argument declarations and function body. */
|
||||||
{
|
{
|
||||||
|
int C99MainFunc = 0;/* Flag for C99 main function returning int */
|
||||||
SymEntry* Param;
|
SymEntry* Param;
|
||||||
|
|
||||||
/* Get the function descriptor from the function entry */
|
/* Get the function descriptor from the function entry */
|
||||||
|
@ -434,6 +435,14 @@ void NewFunc (SymEntry* Func)
|
||||||
if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
|
if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
|
||||||
g_importmainargs ();
|
g_importmainargs ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Determine if this is a main function in a C99 environment that
|
||||||
|
* returns an int.
|
||||||
|
*/
|
||||||
|
if (IsTypeInt (F_GetReturnType (CurrentFunc)) &&
|
||||||
|
IS_Get (&Standard) == STD_C99) {
|
||||||
|
C99MainFunc = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate code and data segments for this function */
|
/* Allocate code and data segments for this function */
|
||||||
|
@ -517,13 +526,23 @@ void NewFunc (SymEntry* Func)
|
||||||
Statement (0);
|
Statement (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is not a void function, output a warning if we didn't see a
|
/* If this is not a void function, and not the main function in a C99
|
||||||
* return statement.
|
* environment returning int, output a warning if we didn't see a return
|
||||||
|
* statement.
|
||||||
*/
|
*/
|
||||||
if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc)) {
|
if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc) && !C99MainFunc) {
|
||||||
Warning ("Control reaches end of non-void function");
|
Warning ("Control reaches end of non-void function");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If this is the main function in a C99 environment returning an int, let
|
||||||
|
* it always return zero. Note: Actual return statements jump to the return
|
||||||
|
* label defined below.
|
||||||
|
* The code is removed by the optimizer if unused.
|
||||||
|
*/
|
||||||
|
if (C99MainFunc) {
|
||||||
|
g_getimmed (CF_INT | CF_CONST, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Output the function exit code label */
|
/* Output the function exit code label */
|
||||||
g_defcodelabel (F_GetRetLab (CurrentFunc));
|
g_defcodelabel (F_GetRetLab (CurrentFunc));
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,9 @@ void F_ReturnFound (Function* F);
|
||||||
int F_HasReturn (const Function* F);
|
int F_HasReturn (const Function* F);
|
||||||
/* Return true if the function contains a return statement*/
|
/* Return true if the function contains a return statement*/
|
||||||
|
|
||||||
|
int F_IsMainFunc (const Function* F);
|
||||||
|
/* Return true if this is the main function */
|
||||||
|
|
||||||
int F_IsVariadic (const Function* F);
|
int F_IsVariadic (const Function* F);
|
||||||
/* Return true if this is a variadic function */
|
/* Return true if this is a variadic function */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue