1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-07 15:25:31 +00:00

Fixed type comparisons of typedefs and arrays.

This commit is contained in:
acqn
2020-08-08 06:46:55 +08:00
committed by Oliver Schmidt
parent eb4464e828
commit 03b37cf712
3 changed files with 45 additions and 43 deletions

View File

@@ -558,6 +558,21 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
unsigned E_SCType = Entry->Flags & SC_TYPEMASK;
unsigned SCType = Flags & SC_TYPEMASK;
/* Existing typedefs cannot be redeclared as anything different */
if (E_SCType == SC_TYPEDEF) {
if (SCType == SC_TYPEDEF) {
if (TypeCmp (E_Type, T) < TC_IDENTICAL) {
Error ("Conflicting types for typedef '%s'", Entry->Name);
Entry = 0;
}
} else {
Error ("Redefinition of typedef '%s' as different kind of symbol", Entry->Name);
Entry = 0;
}
} else {
/* Some symbols may be redeclared if certain requirements are met */
if (IsTypeArray (T) && IsTypeArray (E_Type)) {
@@ -571,7 +586,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
*/
if ((Size != UNSPECIFIED && ESize != UNSPECIFIED && Size != ESize) ||
TypeCmp (T + 1, E_Type + 1) < TC_EQUAL) {
/* Types not identical: Conflicting types */
/* Conflicting element types */
Error ("Conflicting array types for '%s[]'", Entry->Name);
Entry = 0;
} else {
@@ -582,10 +597,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
}
}
} else {
/* We have a symbol with this name already */
if ((Entry->Flags & SC_FUNC) == SC_FUNC) {
} else if ((Entry->Flags & SC_FUNC) == SC_FUNC) {
/* In case of a function, use the new type descriptor, since it
** contains pointers to the new symbol tables that are needed if
@@ -616,22 +628,9 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags
Entry = 0;
}
} else if (E_SCType == SC_TYPEDEF) {
if (SCType == SC_TYPEDEF) {
/* New typedef must be identical */
if (TypeCmp (E_Type, T) < TC_EQUAL) {
Error ("Conflicting types for typedef '%s'", Entry->Name);
Entry = 0;
}
} else {
Error ("Redefinition of typedef '%s' as different kind of symbol", Entry->Name);
Entry = 0;
}
} else {
/* New type must be identical */
/* New type must be equivalent */
if (SCType != E_SCType) {
Error ("Redefinition of '%s' as different kind of symbol", Entry->Name);
Entry = 0;

View File

@@ -190,6 +190,7 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
*/
if (LeftType == T_TYPE_PTR && RightType == T_TYPE_ARRAY) {
RightType = T_TYPE_PTR;
SetResult (Result, TC_STRICT_COMPATIBLE);
}
/* If the underlying types are not identical, the types are incompatible */
@@ -350,13 +351,15 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
/* Check member count */
LeftCount = GetElementCount (lhs);
RightCount = GetElementCount (rhs);
if (LeftCount != RightCount) {
if (LeftCount != UNSPECIFIED &&
RightCount != UNSPECIFIED &&
LeftCount != RightCount) {
RightCount != UNSPECIFIED) {
/* Member count given but different */
SetResult (Result, TC_INCOMPATIBLE);
return;
}
SetResult (Result, TC_EQUAL);
}
break;
case T_TYPE_STRUCT:

View File

@@ -55,7 +55,7 @@ typedef enum {
TC_COMPATIBLE = TC_SIGN_DIFF, /* Compatible types */
TC_QUAL_DIFF, /* Types differ in qualifier of pointer */
TC_STRICT_COMPATIBLE, /* Strict compatibility */
TC_EQUAL, /* Types are equal */
TC_EQUAL, /* Types are equivalent */
TC_IDENTICAL /* Types are identical */
} typecmp_t;