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] Fix pretty printing of array types


Hi!

As shown on the testcase below, c-pretty-print.c currently prints for array
types the max index value rather than the size of the array, so GCC warns
about packed attribute being ignored for field of type `unsigned char[0u]'
when the type is actually unsigned char[1], etc.
The following patch fixes that, ok for trunk?

Bootstrapped/regtested on x86_64-linux.

2006-04-19  Jakub Jelinek  <jakub@redhat.com>

	* c-pretty-print.c (pp_c_direct_abstract_declarator): Print
	TYPE_MAX_VALUE (TYPE_DOMAIN (t)) + 1 for ARRAY_TYPE rather
	than plain TYPE_MAX_VALUE (TYPE_DOMAIN (t)).

--- gcc/c-pretty-print.c.jj	2006-02-16 08:22:59.000000000 +0100
+++ gcc/c-pretty-print.c	2006-04-19 19:01:06.000000000 +0200
@@ -521,7 +521,16 @@ pp_c_direct_abstract_declarator (c_prett
     case ARRAY_TYPE:
       pp_c_left_bracket (pp);
       if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
-        pp_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
+	{
+	  tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
+	  tree type = TREE_TYPE (maxval);
+
+	  if (host_integerp (maxval, 0))
+	    pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
+	  else
+	    pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
+					    build_int_cst (type, 1)));
+	}
       pp_c_right_bracket (pp);
       pp_direct_abstract_declarator (pp, TREE_TYPE (t));
       break;
--- gcc/testsuite/gcc.dg/20060419-1.c.jj	2006-04-19 19:04:58.000000000 +0200
+++ gcc/testsuite/gcc.dg/20060419-1.c	2006-04-19 19:05:50.000000000 +0200
@@ -0,0 +1,4 @@
+struct T {
+  unsigned char f[1] __attribute__((packed)); /* { dg-warning "ignored for field of type.*unsigned char\\\[1\\\]" } */
+  unsigned char g[14] __attribute__((packed)); /* { dg-warning "ignored for field of type.*unsigned char\\\[14\\\]" } */
+};

	Jakub


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