This is the mail archive of the
mailing list for the GCC project.
[PATCH] improve C++ code by changing fold-const.c
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: "gcc-patches at gcc dot gnu dot org Patches" <gcc-patches at gcc dot gnu dot org>
- Cc: Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Sun, 16 May 2004 19:20:41 -0400
- Subject: [PATCH] improve C++ code by changing fold-const.c
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
pass did was changing the type of an ADDR_EXPR.
This patch fixes that and it also fixes a large number of C++ code
PR14042 and PR14729 are both fixed by this simple patch.
OK? Bootstrapped on powerpc-apple-darwin with no regressions.
* fold-const.c (fold) [Case NOP_EXPR]: Handle ADDR_EXPR.
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)