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
This commit is contained in:
uz
2009-10-05 18:46:39 +00:00
parent 8dd3cc35dc
commit 9c5224165f

View File

@@ -797,6 +797,7 @@ static void ArrayRef (ExprDesc* Expr)
ExprDesc Subscript; ExprDesc Subscript;
CodeMark Mark1; CodeMark Mark1;
CodeMark Mark2; CodeMark Mark2;
TypeCode Qualifiers;
Type* ElementType; Type* ElementType;
Type* tptr1; Type* tptr1;
@@ -838,12 +839,16 @@ static void ArrayRef (ExprDesc* Expr)
* Since we do the necessary checking here, we can rely later on the * Since we do the necessary checking here, we can rely later on the
* correct types. * correct types.
*/ */
Qualifiers = T_QUAL_NONE;
if (IsClassPtr (Expr->Type)) { if (IsClassPtr (Expr->Type)) {
if (!IsClassInt (Subscript.Type)) { if (!IsClassInt (Subscript.Type)) {
Error ("Array subscript is not an integer"); Error ("Array subscript is not an integer");
/* To avoid any compiler errors, make the expression a valid int */ /* To avoid any compiler errors, make the expression a valid int */
ED_MakeConstAbsInt (&Subscript, 0); ED_MakeConstAbsInt (&Subscript, 0);
} }
if (IsTypeArray (Expr->Type)) {
Qualifiers = GetQualifier (Expr->Type);
}
ElementType = Indirect (Expr->Type); ElementType = Indirect (Expr->Type);
} else if (IsClassInt (Expr->Type)) { } else if (IsClassInt (Expr->Type)) {
if (!IsClassPtr (Subscript.Type)) { if (!IsClassPtr (Subscript.Type)) {
@@ -852,6 +857,8 @@ static void ArrayRef (ExprDesc* Expr)
* address 0. * address 0.
*/ */
ED_MakeConstAbs (&Subscript, 0, GetCharArrayType (1)); ED_MakeConstAbs (&Subscript, 0, GetCharArrayType (1));
} else if (IsTypeArray (Subscript.Type)) {
Qualifiers = GetQualifier (Subscript.Type);
} }
ElementType = Indirect (Subscript.Type); ElementType = Indirect (Subscript.Type);
} else { } else {
@@ -864,6 +871,14 @@ static void ArrayRef (ExprDesc* Expr)
ElementType = Indirect (Expr->Type); 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 the subscript is a bit-field, load it and make it an rvalue */
if (ED_IsBitField (&Subscript)) { if (ED_IsBitField (&Subscript)) {
LoadExpr (CF_NONE, &Subscript); LoadExpr (CF_NONE, &Subscript);