[PATCH] Fix PR tree-optimization/24162

Richard Guenther rguenther@suse.de
Tue Oct 4 13:41:00 GMT 2005


This fixes the PR by making sure we fold "foo"[0] to 'f' during
fold_indirect_ref.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.


2005-10-04  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/24172
	* fold-const.c (fold_indirect_ref_1): Make sure we fold
	ARRAY_REFs of constant strings.

	* g++.dg/tree-ssa/pr24172.C: New testcase.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.626
diff -c -3 -p -r1.626 fold-const.c
*** fold-const.c	26 Sep 2005 01:28:38 -0000	1.626
--- fold-const.c	4 Oct 2005 10:59:06 -0000
*************** fold_indirect_ref_1 (tree type, tree op0
*** 11511,11519 ****
      {
        tree op = TREE_OPERAND (sub, 0);
        tree optype = TREE_TYPE (op);
!       /* *&p => p */
        if (type == optype)
! 	return op;
        /* *(foo *)&fooarray => fooarray[0] */
        else if (TREE_CODE (optype) == ARRAY_TYPE
  	       && type == TREE_TYPE (optype))
--- 11511,11525 ----
      {
        tree op = TREE_OPERAND (sub, 0);
        tree optype = TREE_TYPE (op);
!       /* *&p => p;  make sure to handle *&"str"[cst] here.  */
        if (type == optype)
! 	{
! 	  tree fop = fold_read_from_constant_string (op);
! 	  if (fop)
! 	    return fop;
! 	  else
! 	    return op;
! 	}
        /* *(foo *)&fooarray => fooarray[0] */
        else if (TREE_CODE (optype) == ARRAY_TYPE
  	       && type == TREE_TYPE (optype))


/* { dg-do compile } */
/* { dg-options "-O2" } */

void IOException( char);
inline int* dummy( const char* const mode )
{
  IOException(*mode+*mode);
}

void prepare_inpaint( )
{
  dummy ("rb");
}



More information about the Gcc-patches mailing list