This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch - [PR 12165] Typedef'ed array variables ignore typedef's const qualifier


Hi,

This is slightly improved patch. With the earlier patch, the strip_array_types() is called 3 times, once for each type qualifier. Now it is being called once.

-Dhananjay

2003-09-22  Dhananjay Deshpande <dhananjayd@kpitcummins.com>

        PR c/12165
        * c-decl.c (grokdeclarator): Set type qualifiers of array elements to array_type

==================================================================================
--- gcc/c-decl.c.old	Fri Sep 19 12:46:51 2003
+++ gcc/c-decl.c	Mon Sep 22 12:28:37 2003
@@ -3621,6 +3621,12 @@ grokdeclarator (tree declarator, tree de
 		| (restrictp ? TYPE_QUAL_RESTRICT : 0)
 		| (volatilep ? TYPE_QUAL_VOLATILE : 0));
 
+  {
+    /* Apply qualifiers of array elements to array type */
+    tree element_type = strip_array_types (type);
+    type_quals |= TYPE_QUALS (element_type);
+  }
+
   /* Warn if two storage classes are given. Default to `auto'.  */
 
   {
==================================================================================

> -----Original Message-----

Hi,

If code below is compiled with gcc

---------------------------------------
typedef const int ACINT[2] ;
static ACINT myArray = {2,4};
---------------------------------------

the array myArray should be in rodata section but it is placed in data section.
With g++, myArray is placed in rodata section.

The problem only appears for typedef const array_type.

The patch below, regtested on i686-pc-linux-gnu works for me. It is based on the  cc1plus implemetation.

The problem is observed in both 3.3 and 3.4.

-Dhananjay

2003-09-19  Dhananjay Deshpande <dhananjayd@kpitcummins.com>

        PR c/12165
        * c-decl.c (grokdeclarator): Set type qualifiers of array elements to array_type

==================================================================================
--- gcc/c-decl.c.old	2003-09-19 14:51:04.000000000 +0530
+++ gcc/c-decl.c	2003-09-19 14:52:04.000000000 +0530
@@ -3621,6 +3621,9 @@
 		| (restrictp ? TYPE_QUAL_RESTRICT : 0)
 		| (volatilep ? TYPE_QUAL_VOLATILE : 0));
 
+  /* Apply qualifiers of array elements to array type */
+  type_quals |= TYPE_QUALS (strip_array_types (type));
+
   /* Warn if two storage classes are given. Default to `auto'.  */
 
   {
==================================================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]