[PATCH] Remove bogus PLUS_EXPR -> POINTER_PLUS_EXPR folding

Richard Guenther rguenther@suse.de
Fri Jan 16 17:43:00 GMT 2009


On Fri, 16 Jan 2009, Richard Guenther wrote:

> 
> This removes a bogus folding that causes miscompiles of libstdc++
> testcases with the ext_pointer class (PR38835) and non-field-sensitive 
> PTA (field-sensitive PTA is too dumb).  I probably anticipated the
> problem in PR36227 which should be fixed with that patch as well.
> 
> Fold changes
> 
>    return <retval> = (const struct _Fwd_list_node_base *) ((long unsigned int) this + (long unsigned int) ((const struct _Relative_pointer_impl *) this)->_M_diff);
> 
> to
> 
>    (const struct _Fwd_list_node_base *) this p+ (long unsigned int) ((const struct _Relative_pointer_impl *) this)->_M_diff
> 
> which makes PTA correctly conclude that 'this' and the result of the
> POINTER_PLUS_EXPR point to the same object.  Which they do not - the source
> used addition in (long unsigned int) to avoid this issue and the resulting
> pointer points somewhere else.
> 
> Fixed by removing the folding.  This also fixes -Wsystem-header warnings
> and miscompiles for the libstdc++ testsuite.
> 
> Bootstrap and regtest on x86_64-unknown-linux-gnu ongoing.

Needs one extra hunk in the Java frontend.  Bootstrapped and tested
on x86_64-unknown-linux-gnu, is that ok for trunk?

Also needs one C++ testcase XFAILed, the FE passes
(long int) &16B->y - 16 into fold and expects us to perform offsetof
magic.  I will try to address both XFAILs later.

Thanks,
Richard.

2009-01-16  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/38835
	PR middle-end/36227

	java/
	* builtins.c (build_addr_sum): Use POINTER_PLUS_EXPR.

Index: gcc/java/builtins.c
===================================================================
*** gcc/java/builtins.c	(revision 143429)
--- gcc/java/builtins.c	(working copy)
*************** static tree
*** 265,273 ****
  build_addr_sum (tree type, tree addr, tree offset)
  {
    tree ptr_type = build_pointer_type (type);
!   return  fold_build2 (PLUS_EXPR, 
! 		       ptr_type, 
! 		       fold_convert (ptr_type, addr), offset);
  }
  
  /* Make sure that this-arg is non-NULL.  This is a security check.  */
--- 265,274 ----
  build_addr_sum (tree type, tree addr, tree offset)
  {
    tree ptr_type = build_pointer_type (type);
!   return fold_build2 (POINTER_PLUS_EXPR,
! 		      ptr_type,
! 		      fold_convert (ptr_type, addr),
! 		      fold_convert (sizetype, offset));
  }
  
  /* Make sure that this-arg is non-NULL.  This is a security check.  */



More information about the Gcc-patches mailing list