From: uz Date: Mon, 5 Oct 2009 18:46:39 +0000 (+0000) Subject: Fixed a bug: A similar problem as that with structs does also exist for X-Git-Tag: V2.13.1~185 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9c5224165fe17e698a5530ee473087b479959161;p=cc65 Fixed a bug: A similar problem as that with structs does also exist for arrays. An array element has all qualifiers from itself and from the array declaration. git-svn-id: svn://svn.cc65.org/cc65/trunk@4334 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/expr.c b/src/cc65/expr.c index cf417577f..298c7f6ac 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -797,6 +797,7 @@ static void ArrayRef (ExprDesc* Expr) ExprDesc Subscript; CodeMark Mark1; CodeMark Mark2; + TypeCode Qualifiers; Type* ElementType; Type* tptr1; @@ -838,12 +839,16 @@ static void ArrayRef (ExprDesc* Expr) * Since we do the necessary checking here, we can rely later on the * correct types. */ + Qualifiers = T_QUAL_NONE; if (IsClassPtr (Expr->Type)) { if (!IsClassInt (Subscript.Type)) { Error ("Array subscript is not an integer"); /* To avoid any compiler errors, make the expression a valid int */ ED_MakeConstAbsInt (&Subscript, 0); } + if (IsTypeArray (Expr->Type)) { + Qualifiers = GetQualifier (Expr->Type); + } ElementType = Indirect (Expr->Type); } else if (IsClassInt (Expr->Type)) { if (!IsClassPtr (Subscript.Type)) { @@ -852,6 +857,8 @@ static void ArrayRef (ExprDesc* Expr) * address 0. */ ED_MakeConstAbs (&Subscript, 0, GetCharArrayType (1)); + } else if (IsTypeArray (Subscript.Type)) { + Qualifiers = GetQualifier (Subscript.Type); } ElementType = Indirect (Subscript.Type); } else { @@ -863,6 +870,14 @@ static void ArrayRef (ExprDesc* Expr) ED_MakeConstAbsInt (&Subscript, 0); ElementType = Indirect (Expr->Type); } + + /* The element type has the combined qualifiers from itself and the array, + * it is a member of (if any). + */ + if (GetQualifier (ElementType) != (GetQualifier (ElementType) | Qualifiers)) { + ElementType = TypeDup (ElementType); + ElementType->C |= Qualifiers; + } /* If the subscript is a bit-field, load it and make it an rvalue */ if (ED_IsBitField (&Subscript)) {