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]

[PATCH][C] Fix PR33726, stipping qualifiers in building ARRAY_REFs


The C FE currently strips qualifiers from the array element type for
the type used for building an ARRAY_REF.  This causes the type-checker
to complain about mismatches if you later take the address of the
referenced element.

Fixed by simply not stripping qualifiers here (why would we do so
anyway?).

Bootstrap / regtest on x86_64-unknown-linux-gnu in progress, ok for
mainline if it passes?

Thanks,
Richard.

2007-10-10  Richard Guenther  <rguenther@suse.de>

	PR c/33726
	* c-typeck.c (build_array_ref): Do not strip qualifiers from
	the array element type.

	* gcc.dg/pr33726.c: New testcase.

Index: c-typeck.c
===================================================================
*** c-typeck.c	(revision 129199)
--- c-typeck.c	(working copy)
*************** build_array_ref (tree array, tree index)
*** 2113,2120 ****
  	}
  
        type = TREE_TYPE (TREE_TYPE (array));
-       if (TREE_CODE (type) != ARRAY_TYPE)
- 	type = TYPE_MAIN_VARIANT (type);
        rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
        /* Array ref is const/volatile if the array elements are
  	 or if the array is.  */
--- 2113,2118 ----
Index: testsuite/gcc.dg/pr33726.c
===================================================================
*** testsuite/gcc.dg/pr33726.c	(revision 0)
--- testsuite/gcc.dg/pr33726.c	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile } */
+ 
+ /* We used to ICE here with type-checking enabled.  */
+ 
+ typedef unsigned int U032;
+ typedef volatile struct X {
+      U032 Monochrome[1];
+      struct {
+           U032 WidthHeight;
+      } UnclippedRectangle[1];
+ } RivaBitmap;
+ void writel(void *);
+ void rivafb_fillrect(RivaBitmap *bm)
+ {
+   writel((void *)&bm->UnclippedRectangle[0].WidthHeight);
+ }
+ 


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