]> git.sur5r.net Git - cc65/commitdiff
Fixed an error: When determining where to place initialized data, the compiler
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 24 Mar 2012 14:28:59 +0000 (14:28 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 24 Mar 2012 14:28:59 +0000 (14:28 +0000)
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

src/cc65/compile.c
src/cc65/datatype.c
src/cc65/datatype.h
src/cc65/locals.c

index d7167706b21de9ca4ec2e9ba05944fe201ee3c29..f619d5b59b03bc9095178b618a2c6b607b049292 100644 (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 ();
index 0d7b27c6021b0aec761a2cfd340b9b15117fe1fc..c1f86062fc10b571b4ad355a947101ba8cb009e5 100644 (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 */
 {
index 0fe46f6d2b0b781ed53a6424b6d350ad8bae888e..3cc6ec5b59c992c9393f451d6aef4d14d5f29664 100644 (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 */
 
index 710d05e33a34a7442bbaee93f432246fd2c08378..3e1002add806d9cff078220ad2d448297e0b24e9 100644 (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);