Fixed an error: When determining where to place initialized data, the compiler

didn't look "deep enough" into nested arrays to determine the constness
correctly.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5622 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2012-03-24 14:28:59 +00:00
parent 515661e5f4
commit 724d1b9160
4 changed files with 30 additions and 13 deletions

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2000-2009, Ullrich von Bassewitz */
/* (C) 2000-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -93,7 +93,7 @@ static void Parse (void)
/* Disallow ASM statements on global level */
if (CurTok.Tok == TOK_ASM) {
Error ("__asm__ is not allowed here");
Error ("__asm__ is not allowed here");
/* Parse and remove the statement for error recovery */
AsmStatement ();
ConsumeSemi ();
@ -209,9 +209,7 @@ static void Parse (void)
* the element qualifiers, since not the array but its
* elements are const.
*/
if (IsQualConst (Decl.Type) ||
(IsTypeArray (Decl.Type) &&
IsQualConst (GetElementType (Decl.Type)))) {
if (IsQualConst (GetBaseElementType (Decl.Type))) {
g_userodata ();
} else {
g_usedata ();

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2008 Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -654,6 +654,20 @@ Type* GetElementType (Type* T)
Type* GetBaseElementType (Type* T)
/* Return the base element type of a given type. If T is not an array, this
* will return. Otherwise it will return the base element type, which means
* the element type that is not an array.
*/
{
while (IsTypeArray (T)) {
++T;
}
return T;
}
SymEntry* GetSymEntry (const Type* T)
/* Return a SymEntry pointer from a type */
{

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2010, Ullrich von Bassewitz */
/* (C) 1998-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -640,6 +640,12 @@ void SetElementCount (Type* T, long Count);
Type* GetElementType (Type* T);
/* Return the element type of the given array type. */
Type* GetBaseElementType (Type* T);
/* Return the base element type of a given type. If T is not an array, this
* will return. Otherwise it will return the base element type, which means
* the element type that is not an array.
*/
struct SymEntry* GetSymEntry (const Type* T) attribute ((const));
/* Return a SymEntry pointer from a type */

View File

@ -356,11 +356,10 @@ static unsigned ParseStaticDecl (Declaration* Decl, unsigned* SC)
if (CurTok.Tok == TOK_ASSIGN) {
/* Initialization ahead, switch to data segment and define a label.
* For arrays, we need to check the elements of the array for
* For arrays, we need to check the elements of the array for
* constness, not the array itself.
*/
if (IsQualConst (Decl->Type) ||
(IsTypeArray (Decl->Type) && IsQualConst (GetElementType (Decl->Type)))) {
if (IsQualConst (GetBaseElementType (Decl->Type))) {
SymData = AllocLabel (g_userodata);
} else {
SymData = AllocLabel (g_usedata);