[ast-optimizer-branch]: Your change to c-pretty-print.c is broken.

Frank Ch. Eigler fche@redhat.com
Mon Jun 17 08:58:00 GMT 2002


Hi -

Here is a new patch for this problem.  Some experiments tell me
that there is no simple way to correctly map from INTEGER_CST
nodes to a proper literal.  This new patch therefore punts on
the problem.  The included comment block gives a little more of
the sob story.  What do you think?


2002-06-17  Frank Ch. Eigler  <fche@redhat.com>

	* c-pretty-print.c (dump_c_node): Print pointer-type
	integer constants as raw numbers with a "B" (bytes) suffix.

Index: c-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-pretty-print.c,v
retrieving revision 1.1.2.20
diff -u -r1.1.2.20 c-pretty-print.c
--- c-pretty-print.c	15 Jun 2002 13:08:59 -0000	1.1.2.20
+++ c-pretty-print.c	17 Jun 2002 15:51:56 -0000
@@ -354,10 +356,32 @@
 
     case INTEGER_CST:
       if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
-	/* In the case of a pointer, divide by the size of the pointed-to type.  */
-	output_decimal (buffer,
-			TREE_INT_CST_LOW (node) * BITS_PER_UNIT /
-			(TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node)))));
+	{
+	  /* In the case of a pointer, one may want to divide by the
+	     size of the pointed-to type.  Unfortunately, this not
+	     straightforward.  The C front-end maps expressions 
+
+	     (int *) 5
+	     int *p; (p + 5)
+
+	     in such a way that the two INTEGER_CST nodes for "5" have
+	     different values but identical types.  In the latter
+	     case, the 5 is multipled by sizeof (int) in c-common.c
+	     (pointer_int_sum) to convert it to a byte address, and
+	     yet the type of the node is left unchanged.  Argh.  What
+	     is consistent though is that the number value corresponds
+	     to bytes (UNITS) offset.
+
+	     NB: Neither of the following divisors can be trivially
+	     used to recover the original literal:
+
+             TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
+             TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node)))
+	  */
+
+	  output_decimal (buffer, TREE_INT_CST_LOW (node));
+	  output_add_string (buffer, "B"); /* pseudo-unit */
+	}
       else
 	output_decimal (buffer, TREE_INT_CST_LOW (node));
       break;


- FChE



More information about the Gcc-patches mailing list