re PR tree-optimization/38835 (field-insensitive PTA causes libstdc++ miscompiles)

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

	PR tree-optimization/38835
	PR middle-end/36227
	* fold-const.c (fold_binary): Remove PTR + INT -> (INT)(PTR p+ INT)
	and INT + PTR -> (INT)(PTR p+ INT) folding.
	* tree-ssa-address.c (create_mem_ref): Properly use POINTER_PLUS_EXPR.

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

	* gcc.c-torture/execute/pr36227.c: New testcase.
	* gcc.dg/tree-ssa/foldaddr-1.c: XFAIL.
	* g++.dg/init/const7.C: Likewise.

From-SVN: r143442
This commit is contained in:
Richard Guenther 2009-01-16 19:18:18 +00:00 committed by Richard Biener
parent c1cb09ada0
commit 786ce82d44
9 changed files with 46 additions and 22 deletions

View File

@ -1,3 +1,11 @@
2009-01-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/38835
PR middle-end/36227
* fold-const.c (fold_binary): Remove PTR + INT -> (INT)(PTR p+ INT)
and INT + PTR -> (INT)(PTR p+ INT) folding.
* tree-ssa-address.c (create_mem_ref): Properly use POINTER_PLUS_EXPR.
2009-01-16 Adam Nemet <anemet@caviumnetworks.com>
PR target/38554

View File

@ -9864,20 +9864,6 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return NULL_TREE;
case PLUS_EXPR:
/* PTR + INT -> (INT)(PTR p+ INT) */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
&& INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
return fold_convert (type, fold_build2 (POINTER_PLUS_EXPR,
TREE_TYPE (arg0),
arg0,
fold_convert (sizetype, arg1)));
/* INT + PTR -> (INT)(PTR p+ INT) */
if (POINTER_TYPE_P (TREE_TYPE (arg1))
&& INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
return fold_convert (type, fold_build2 (POINTER_PLUS_EXPR,
TREE_TYPE (arg1),
arg1,
fold_convert (sizetype, arg0)));
/* A + (-B) -> A - B */
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2 (MINUS_EXPR, type,

View File

@ -1,3 +1,9 @@
2009-01-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/38835
PR middle-end/36227
* builtins.c (build_addr_sum): Use POINTER_PLUS_EXPR.
2008-12-05 Sebastian Pop <sebastian.pop@amd.com>
PR bootstrap/38262

View File

@ -265,9 +265,10 @@ static tree
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);
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. */

View File

@ -1,3 +1,11 @@
2009-01-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/38835
PR middle-end/36227
* gcc.c-torture/execute/pr36227.c: New testcase.
* gcc.dg/tree-ssa/foldaddr-1.c: XFAIL.
* g++.dg/init/const7.C: Likewise.
2009-01-16 Adam Nemet <anemet@caviumnetworks.com>
PR target/38554

View File

@ -9,5 +9,5 @@ short offsets[1] = {
// This ensures that we get a dump whether or not the bug is present.
void fn() { }
// { dg-final { scan-tree-dump-not "initialization" "gimple" } }
// { dg-final { scan-tree-dump-not "initialization" "gimple" { xfail *-*-* } } }
// { dg-final { cleanup-tree-dump "gimple" } }

View File

@ -0,0 +1,15 @@
#include <stdint.h>
extern void abort (void);
int main()
{
int i = 1;
int *p = &i;
uintptr_t iptr;
iptr = (uintptr_t)p - (uintptr_t)&iptr;
p = (int *)((uintptr_t)&iptr + iptr);
if (*p != 1)
abort ();
return 0;
}

View File

@ -11,6 +11,6 @@ int foo(char *b)
/* Folding should have determined that the two addresses were
not identical and thus collapsed the function into a trivial
"return 0". */
/* { dg-final { scan-tree-dump-times "return 0" 1 "original"} } */
/* { dg-final { scan-tree-dump-times "return 0" 1 "original" { xfail *-*-* } } */
/* { dg-final { cleanup-tree-dump "original" } } */

View File

@ -619,9 +619,9 @@ create_mem_ref (gimple_stmt_iterator *gsi, tree type, aff_tree *addr,
{
atype = TREE_TYPE (tmp);
parts.base = force_gimple_operand_gsi (gsi,
fold_build2 (PLUS_EXPR, atype,
fold_convert (atype, parts.base),
tmp),
fold_build2 (POINTER_PLUS_EXPR, atype,
tmp,
fold_convert (sizetype, parts.base)),
true, NULL_TREE, true, GSI_SAME_STMT);
}
else