fold-const.c (fold, [...]): Do not lose side effects when optimizing 0 % X.

* fold-const.c (fold, case CEIL_MOD_EXPR): Do not lose side
	effects when optimizing 0 % X.  Do not try to optimize X % 0.

	* gcc.c-torture/execute/20050131-1.c: New test.
	* gcc.dg/wcaselabel.c: New test.

From-SVN: r94516
This commit is contained in:
Jeff Law 2005-01-31 20:48:52 -07:00 committed by Jeff Law
parent 3dcec1e9e7
commit dc5d4efbce
5 changed files with 54 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2005-01-31 Jeff Law <law@redhat.com>
* fold-const.c (fold, case CEIL_MOD_EXPR): Do not lose side
effects when optimizing 0 % X. Do not try to optimize X % 0.
2005-01-31 James E. Wilson <wilson@specifixinc.com>
* config/ia64/itanium1.md (1_scall bypass): Change 2_mmalua to

View File

@ -7938,12 +7938,21 @@ fold (tree expr)
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
case TRUNC_MOD_EXPR:
/* 0 % X is always zero as is X % 1. */
if (integer_zerop (arg0) || integer_onep (arg1))
/* X % 1 is always zero, but be sure to preserve any side
effects in X. */
if (integer_onep (arg1))
return omit_one_operand (type, integer_zero_node, arg0);
/* X % 0, return X % 0 unchanged so that we can get the
proper warnings and errors. */
if (integer_zerop (arg1))
return t;
/* 0 % X is always zero, but be sure to preserve any side
effects in X. Place this after checking for X == 0. */
if (integer_zerop (arg0))
return omit_one_operand (type, integer_zero_node, arg1);
/* X % -1 is zero. */
if (!TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == INTEGER_CST

View File

@ -1,3 +1,8 @@
2005-01-31 Jeff Law <law@redhat.com>
* gcc.c-torture/execute/20050131-1.c: New test.
* gcc.dg/wcaselabel.c: New test.
2005-01-31 Mark Mitchell <mark@codesourcery.com>
* g++.dg/other/warning1.C: Adjust error messags.

View File

@ -0,0 +1,18 @@
/* Verify that we do not lose side effects on a MOD expression. */
#include <stdlib.h>
#include <stdio.h>
int
foo (int a)
{
int x = 0 % a++;
return a;
}
main()
{
if (foo (9) != 10)
abort ();
exit (0);
}

View File

@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-w" } */
int foo(int x)
{
switch(x)
{
case 0 % 0: /* { dg-error "case label does not reduce to an integer constant" } */
return 1;
default:
return 2;
}
}