From abcc2a8f1a06083dd8847dab5fd974cd50eba4d8 Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 20 Aug 2020 07:46:08 +0800 Subject: [PATCH] Disallowed void arrays of elements of variant sizes. --- src/cc65/declare.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 6aff1960e..e32c880cc 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -2389,6 +2389,11 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers) } } + /* Size of 'void' elements are determined after initialization */ + if (ElementSize == 0) { + ElementSize = SizeOf (ElementType); + } + if (ElementCount == UNSPECIFIED) { /* Number of elements determined by initializer */ SetElementCount (T, Count); @@ -2695,7 +2700,11 @@ static unsigned ParseVoidInit (Type* T) ConsumeRCurly (); /* Number of bytes determined by initializer */ - T->A.U = Size; + if (T->A.U != 0 && T->A.U != Size) { + Error ("'void' array initialized with elements of variant sizes"); + } else { + T->A.U = Size; + } /* Return the number of bytes initialized */ return Size;