Added several type checks, especially for functions. Moved check for implicit
int return type. git-svn-id: svn://svn.cc65.org/cc65/trunk@3858 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -849,7 +849,7 @@ static void ParseAnsiParamList (FuncDesc* F)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static FuncDesc* ParseFuncDecl (const DeclSpec* Spec)
|
static FuncDesc* ParseFuncDecl (void)
|
||||||
/* Parse the argument list of a function. */
|
/* Parse the argument list of a function. */
|
||||||
{
|
{
|
||||||
unsigned Offs;
|
unsigned Offs;
|
||||||
@@ -881,19 +881,6 @@ static FuncDesc* ParseFuncDecl (const DeclSpec* Spec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for an implicit int return in the function */
|
|
||||||
if ((Spec->Flags & DS_DEF_TYPE) != 0 &&
|
|
||||||
Spec->Type[0].C == T_INT &&
|
|
||||||
Spec->Type[1].C == T_END) {
|
|
||||||
/* Function has an implicit int return. Output a warning if we don't
|
|
||||||
* have the C89 standard enabled explicitly.
|
|
||||||
*/
|
|
||||||
if (IS_Get (&Standard) >= STD_C99) {
|
|
||||||
Warning ("Implicit `int' return type is an obsolete feature");
|
|
||||||
}
|
|
||||||
F->Flags |= FD_OLDSTYLE_INTRET;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse params */
|
/* Parse params */
|
||||||
if ((F->Flags & FD_OLDSTYLE) == 0) {
|
if ((F->Flags & FD_OLDSTYLE) == 0) {
|
||||||
/* New style function */
|
/* New style function */
|
||||||
@@ -1084,7 +1071,7 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Parse the function declaration */
|
/* Parse the function declaration */
|
||||||
F = ParseFuncDecl (Spec);
|
F = ParseFuncDecl ();
|
||||||
|
|
||||||
/* Add the function type. Be sure to bounds check the type buffer */
|
/* Add the function type. Be sure to bounds check the type buffer */
|
||||||
AddFuncTypeToDeclaration (D, F);
|
AddFuncTypeToDeclaration (D, F);
|
||||||
@@ -1160,6 +1147,46 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
/* Fix any type qualifiers attached to an array type */
|
/* Fix any type qualifiers attached to an array type */
|
||||||
FixArrayQualifiers (D->Type);
|
FixArrayQualifiers (D->Type);
|
||||||
|
|
||||||
|
/* Check several things for function or function pointer types */
|
||||||
|
if (IsTypeFunc (D->Type) || IsTypeFuncPtr (D->Type)) {
|
||||||
|
|
||||||
|
/* A function. Check the return type */
|
||||||
|
Type* RetType = GetFuncReturn (D->Type);
|
||||||
|
|
||||||
|
/* Functions may not return functions or arrays */
|
||||||
|
if (IsTypeFunc (RetType)) {
|
||||||
|
Error ("Functions are not allowed to return functions");
|
||||||
|
} else if (IsTypeArray (RetType)) {
|
||||||
|
Error ("Functions are not allowed to return arrays");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The return type must not be qualified */
|
||||||
|
if (GetQualifier (RetType) != T_QUAL_NONE && RetType[1].C == T_END) {
|
||||||
|
|
||||||
|
if (GetType (RetType) == T_TYPE_VOID) {
|
||||||
|
/* A qualified void type is always an error */
|
||||||
|
Error ("function definition has qualified void return type");
|
||||||
|
} else {
|
||||||
|
/* For others, qualifiers are ignored */
|
||||||
|
Warning ("type qualifiers ignored on function return type");
|
||||||
|
RetType[0].C = UnqualifiedType (RetType[0].C);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Warn about an implicit int return in the function */
|
||||||
|
if ((Spec->Flags & DS_DEF_TYPE) != 0 &&
|
||||||
|
RetType[0].C == T_INT && RetType[1].C == T_END) {
|
||||||
|
/* Function has an implicit int return. Output a warning if we don't
|
||||||
|
* have the C89 standard enabled explicitly.
|
||||||
|
*/
|
||||||
|
if (IS_Get (&Standard) >= STD_C99) {
|
||||||
|
Warning ("Implicit `int' return type is an obsolete feature");
|
||||||
|
}
|
||||||
|
GetFuncDesc (D->Type)->Flags |= FD_OLDSTYLE_INTRET;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Check the size of the generated type */
|
/* Check the size of the generated type */
|
||||||
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
if (!IsTypeFunc (D->Type) && !IsTypeVoid (D->Type)) {
|
||||||
unsigned Size = SizeOf (D->Type);
|
unsigned Size = SizeOf (D->Type);
|
||||||
@@ -1171,6 +1198,7 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user