[PATCH] improve C++ code by changing fold-const.c

Andrew Pinski pinskia@physics.uc.edu
Mon May 17 02:32:00 GMT 2004


I found that my cast pass was too complicated and replicated too much in
which was in fold already.  The only thing fold did not handle that my 
cast
pass did was changing the type of an ADDR_EXPR.

This patch fixes that and it also fixes a large number of C++ code 
problems.
PR14042 and PR14729 are both fixed by this simple patch.

OK? Bootstrapped on powerpc-apple-darwin with no regressions.


ChangeLog:

	* fold-const.c (fold) [Case NOP_EXPR]: Handle ADDR_EXPR.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.376
diff -u -p -r1.376 fold-const.c
--- fold-const.c	15 May 2004 23:07:49 -0000	1.376
+++ fold-const.c	16 May 2004 23:09:54 -0000
@@ -5815,6 +5815,17 @@ fold (tree expr)
        if (TREE_TYPE (TREE_OPERAND (t, 0)) == type)
  	return TREE_OPERAND (t, 0);

+      if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
+	{
+	  tree inside_tree = TREE_OPERAND (t, 0);
+	  tree inside_type = TREE_TYPE (inside_tree);
+	  if (POINTER_TYPE_P (inside_type)
+	      && POINTER_TYPE_P (type)
+	      && lang_hooks.types_compatible_p (TREE_TYPE (type),
+						TREE_TYPE (inside_type)))
+	    return build (ADDR_EXPR, type, TREE_OPERAND (inside_tree, 0));
+	}
+
        /* Handle cases of two conversions in a row.  */
        if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
  	  || TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)



More information about the Gcc-patches mailing list