2018-06-21 Richard Biener <rguenther@suse.de>

Backport from mainline
	2018-02-28  Richard Biener  <rguenther@suse.de>

	PR middle-end/84607
	* genmatch.c (capture_info::walk_match): Do not mark
	captured expressions without operands as expr_p given
	they act more like predicates and should be subject to
	"lost tail" side-effect preserving.

	* gcc.dg/pr84607.c: New testcase.

	2018-05-04  Richard Biener  <rguenther@suse.de>

	PR middle-end/85588
	* fold-const.c (negate_expr_p): Restrict negation of operand
	zero of a division to when we know that can happen without
	overflow.
	(fold_negate_expr_1): Likewise.

	* gcc.dg/torture/pr85588.c: New testcase.
	* gcc.dg/torture/pr57656.c: Use dg-additional-options.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@261839 138bc75d-0d04-0410-961f-82ee72b054a4
This commit is contained in:
rguenth 2018-06-21 09:50:36 +00:00
parent 8b44955027
commit 564d3da38c
7 changed files with 69 additions and 6 deletions

View File

@ -1,3 +1,22 @@
2018-06-21 Richard Biener <rguenther@suse.de>
Backport from mainline
2018-02-28 Richard Biener <rguenther@suse.de>
PR middle-end/84607
* genmatch.c (capture_info::walk_match): Do not mark
captured expressions without operands as expr_p given
they act more like predicates and should be subject to
"lost tail" side-effect preserving.
2018-05-04 Richard Biener <rguenther@suse.de>
PR middle-end/85588
* fold-const.c (negate_expr_p): Restrict negation of operand
zero of a division to when we know that can happen without
overflow.
(fold_negate_expr_1): Likewise.
2018-06-21 Richard Biener <rguenther@suse.de>
Backport from mainline

View File

@ -481,12 +481,15 @@ negate_expr_p (tree t)
case EXACT_DIV_EXPR:
if (TYPE_UNSIGNED (type))
break;
if (negate_expr_p (TREE_OPERAND (t, 0)))
/* In general we can't negate A in A / B, because if A is INT_MIN and
B is not 1 we change the sign of the result. */
if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
&& negate_expr_p (TREE_OPERAND (t, 0)))
return true;
/* In general we can't negate B in A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. */
if (! INTEGRAL_TYPE_P (TREE_TYPE (t))
if (! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
|| TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
|| (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& ! integer_onep (TREE_OPERAND (t, 1))))
@ -663,14 +666,17 @@ fold_negate_expr_1 (location_t loc, tree t)
case EXACT_DIV_EXPR:
if (TYPE_UNSIGNED (type))
break;
if (negate_expr_p (TREE_OPERAND (t, 0)))
/* In general we can't negate A in A / B, because if A is INT_MIN and
B is not 1 we change the sign of the result. */
if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
&& negate_expr_p (TREE_OPERAND (t, 0)))
return fold_build2_loc (loc, TREE_CODE (t), type,
negate_expr (TREE_OPERAND (t, 0)),
TREE_OPERAND (t, 1));
/* In general we can't negate B in A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. */
if ((! INTEGRAL_TYPE_P (TREE_TYPE (t))
if ((! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
|| TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
|| (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& ! integer_onep (TREE_OPERAND (t, 1))))

View File

@ -1930,7 +1930,11 @@ capture_info::walk_match (operand *o, unsigned toplevel_arg,
if (c->what
&& (e = dyn_cast <expr *> (c->what)))
{
info[where].expr_p = true;
/* Zero-operand expression captures like ADDR_EXPR@0 are
similar as predicates -- if they are not mentioned in
the result we have to force them to have no side-effects. */
if (e->ops.length () != 0)
info[where].expr_p = true;
info[where].force_single_use |= e->force_single_use;
}
}

View File

@ -1,3 +1,17 @@
2018-06-21 Richard Biener <rguenther@suse.de>
Backport from mainline
2018-02-28 Richard Biener <rguenther@suse.de>
PR middle-end/84607
* gcc.dg/pr84607.c: New testcase.
2018-05-04 Richard Biener <rguenther@suse.de>
PR middle-end/85588
* gcc.dg/torture/pr85588.c: New testcase.
* gcc.dg/torture/pr57656.c: Use dg-additional-options.
2018-06-21 Richard Biener <rguenther@suse.de>
Backport from mainline

View File

@ -0,0 +1,16 @@
/* { dg-do run } */
extern void exit(int);
extern void abort(void);
int a[10];
int foo()
{
exit (0);
return 0;
}
int main()
{
if (&a[foo()])
abort ();
return 0;
}

View File

@ -1,5 +1,5 @@
/* { dg-do run } */
/* { dg-options "-fstrict-overflow" } */
/* { dg-additional-options "-fstrict-overflow" } */
int main (void)
{

View File

@ -0,0 +1,4 @@
/* { dg-do run } */
/* { dg-additional-options "-fwrapv" } */
#include "pr57656.c"