mirror of
https://github.com/cc65/cc65.git
synced 2025-01-05 15:30:44 +00:00
Merge pull request #2265 from acqn/C99Main
[cc65] Enabled implicit "return 0" in C99 standard main function in default cc65 mode
This commit is contained in:
commit
ad0b778008
@ -518,12 +518,22 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
|
|||||||
Error ("'main' cannot be declared as __fastcall__");
|
Error ("'main' cannot be declared as __fastcall__");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If cc65 extensions aren't enabled, don't allow a main function that
|
/* Check return type */
|
||||||
** doesn't return an int.
|
if (GetUnqualRawTypeCode (ReturnType) == T_INT) {
|
||||||
|
/* Determine if this is a main function in a C99 environment that
|
||||||
|
** returns an int.
|
||||||
*/
|
*/
|
||||||
if (IS_Get (&Standard) != STD_CC65 && ReturnType[0].C != T_INT) {
|
if (IS_Get (&Standard) >= STD_C99) {
|
||||||
|
C99MainFunc = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* If cc65 extensions aren't enabled, don't allow a main function
|
||||||
|
** that doesn't return an int.
|
||||||
|
*/
|
||||||
|
if (IS_Get (&Standard) != STD_CC65) {
|
||||||
Error ("'main' must always return an int");
|
Error ("'main' must always return an int");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a forced import of a symbol that is contained in the startup
|
/* Add a forced import of a symbol that is contained in the startup
|
||||||
** code. This will force the startup code to be linked in.
|
** code. This will force the startup code to be linked in.
|
||||||
@ -540,14 +550,6 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
|
|||||||
/* The start-up code doesn't fast-call main(). */
|
/* The start-up code doesn't fast-call main(). */
|
||||||
Func->Type->C |= T_QUAL_CDECL;
|
Func->Type->C |= T_QUAL_CDECL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine if this is a main function in a C99 environment that
|
|
||||||
** returns an int.
|
|
||||||
*/
|
|
||||||
if (GetUnqualRawTypeCode (ReturnType) == T_INT &&
|
|
||||||
IS_Get (&Standard) == STD_C99) {
|
|
||||||
C99MainFunc = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate code and data segments for this function */
|
/* Allocate code and data segments for this function */
|
||||||
@ -652,21 +654,16 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
|
|||||||
AnyStatement (0);
|
AnyStatement (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is not a void function, and not the main function in a C99
|
/* Check if this function is missing a return value */
|
||||||
** environment returning int, output a warning if we didn't see a return
|
if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc)) {
|
||||||
** statement.
|
/* If this is the main function in a C99 environment returning an int,
|
||||||
*/
|
** let it always return zero. Otherwise output a warning.
|
||||||
if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc) && !C99MainFunc && IS_Get (&WarnReturnType)) {
|
|
||||||
Warning ("Control reaches end of non-void function [-Wreturn-type]");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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) {
|
if (C99MainFunc) {
|
||||||
g_getimmed (CF_INT | CF_CONST, 0, 0);
|
g_getimmed (CF_INT | CF_CONST, 0, 0);
|
||||||
|
} else if (IS_Get (&WarnReturnType)) {
|
||||||
|
Warning ("Control reaches end of non-void function [-Wreturn-type]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output the function exit code label */
|
/* Output the function exit code label */
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
and then "make" again to confirm
|
and then "make" again to confirm
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
short main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
printf("%02x", 0x42);
|
printf("%02x", 0x42); /* produce an error */
|
||||||
n = 0; /* produce an error */
|
n = 0; /* produce an error */
|
||||||
/* another error */
|
/* produce a warning */
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,4 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
printf("%02x", 0x42);
|
printf("%02x", 0x42);
|
||||||
/* produce a warning */
|
/* produce a warning */
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
custom-reference.c:24: Warning: Parameter 'argc' is never used
|
custom-reference.c:23: Warning: Parameter 'argc' is never used
|
||||||
custom-reference.c:24: Warning: Parameter 'argv' is never used
|
custom-reference.c:23: Warning: Parameter 'argv' is never used
|
||||||
|
Loading…
Reference in New Issue
Block a user