From 85e63e99a66e71c561aaf6b5fdb5d794bf89acf8 Mon Sep 17 00:00:00 2001 From: acqn Date: Fri, 27 Oct 2023 21:51:45 +0800 Subject: [PATCH] Fixed regression: array element of incomplete type. --- src/cc65/compile.c | 2 +- src/cc65/declare.c | 34 ++++++++++++++++++---------------- test/err/zero-size.c | 6 ++++++ 3 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 test/err/zero-size.c diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 9d7fbe20a..edd00022c 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -511,7 +511,7 @@ void Compile (const char* FileName) /* Mark as defined; so that it will be exported, not imported */ Entry->Flags |= SC_DEF; - } else { + } else if (!IsTypeArray (Entry->Type)) { /* Tentative declared variable is still of incomplete type */ Error ("Definition of '%s' has type '%s' that is never completed", Entry->Name, diff --git a/src/cc65/declare.c b/src/cc65/declare.c index cd174c92d..cf9c13059 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -493,33 +493,35 @@ static void FixQualifiers (Type* DataType) -static void CheckArrayElementType (Type* DataType) +static void CheckArrayElementType (const Type* T) /* Check if data type consists of arrays of incomplete element types */ { - Type* T = DataType; - while (T->C != T_END) { if (IsTypeArray (T)) { + /* If the array is multi-dimensional, keep going until we get the + ** true element type. + */ ++T; - if (IsIncompleteESUType (T)) { - /* We cannot have an array of incomplete elements */ - Error ("Array of incomplete element type '%s'", GetFullTypeName (T)); - } else if (SizeOf (T) == 0) { - /* If the array is multi-dimensional, try to get the true - ** element type. - */ - if (IsTypeArray (T)) { - continue; - } - /* We could support certain 0-size element types as an extension */ - if (!IsTypeVoid (T) || IS_Get (&Standard) != STD_CC65) { - Error ("Array of 0-size element type '%s'", GetFullTypeName (T)); + if (SizeOf (T) == 0) { + if (IsTypeArray (T) || IsIncompleteESUType (T)) { + /* We cannot have an array of incomplete elements */ + if (!IsTypeArray (T) || GetElementCount (T) == UNSPECIFIED) { + Error ("Array of incomplete element type '%s'", + GetFullTypeName (T)); + return; + } + } else if (!IsTypeVoid (T) || IS_Get (&Standard) != STD_CC65) { + /* We could support certain 0-size element types as an extension */ + Error ("Array of 0-size element type '%s'", + GetFullTypeName (T)); + return; } } else { if (IsTypeStruct (T)) { SymEntry* TagEntry = GetESUTagSym (T); if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) { Error ("Invalid use of struct with flexible array member"); + return; } } } diff --git a/test/err/zero-size.c b/test/err/zero-size.c new file mode 100644 index 000000000..9e7510c91 --- /dev/null +++ b/test/err/zero-size.c @@ -0,0 +1,6 @@ +char a[][] = { 0, 0 }; /* Error: Array type has incomplete element type 'char[]' */ + +int main(void) +{ + return 0; +}