PATCH RFC: Use parentheses in dumps for same-priority operands

Ian Lance Taylor iant@google.com
Wed Jan 10 04:35:00 GMT 2007


While looking at some floating point code recently, I was surprised to
see that the dump files do not report how operators of the same
precedence associate.  This of course matters for floating point.  The
compiler represents it correctly, it is just not printed in the dump
files.

For example, for this test case:

double foo (double a, double b, double c) { return (a - (b - c)); }

The final_cleanup dump file includes this:

foo (a, b, c)
{
<bb 2>:
  return a - b - c;

}

With this trivial patch, the dump file looks like this:

foo (a, b, c)
{
<bb 2>:
  return a - (b - c);

}

This correctly represents the order of operations.

I've tested this patch with a bootstrap and testsuite run on
i686-pc-linux-gnu.  I plan to commit it in a day or two unless
somebody objects.

Ian


2007-01-09  Ian Lance Taylor  <iant@google.com>

	* tree-pretty-print.c (dump_generic_node): Print parentheses when
	operands have the same priority.


Index: gcc/tree-pretty-print.c
===================================================================
--- gcc/tree-pretty-print.c	(revision 120620)
+++ gcc/tree-pretty-print.c	(working copy)
@@ -1259,7 +1259,7 @@ dump_generic_node (pretty_printer *buffe
 
 	/* When the operands are expressions with less priority,
 	   keep semantics of the tree representation.  */
-	if (op_prio (op0) < op_prio (node))
+	if (op_prio (op0) <= op_prio (node))
 	  {
 	    pp_character (buffer, '(');
 	    dump_generic_node (buffer, op0, spc, flags, false);
@@ -1274,7 +1274,7 @@ dump_generic_node (pretty_printer *buffe
 
 	/* When the operands are expressions with less priority,
 	   keep semantics of the tree representation.  */
-	if (op_prio (op1) < op_prio (node))
+	if (op_prio (op1) <= op_prio (node))
 	  {
 	    pp_character (buffer, '(');
 	    dump_generic_node (buffer, op1, spc, flags, false);



More information about the Gcc-patches mailing list