mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-31 11:50:57 +08:00
middle-end/96369 - fix missed short-circuiting during range folding
This makes the special case of constant evaluated LHS for a short-circuiting or/and explicit rather than doing range merging and eventually exposing a side-effect that shouldn't be evaluated. 2020-07-31 Richard Biener <rguenther@suse.de> PR middle-end/96369 * fold-const.c (fold_range_test): Special-case constant LHS for short-circuiting operations. * c-c++-common/pr96369.c: New testcase.
This commit is contained in:
parent
bc2b1a232b
commit
10231958fc
@ -5931,6 +5931,13 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
|
||||
return 0;
|
||||
|
||||
lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
|
||||
/* If op0 is known true or false and this is a short-circuiting
|
||||
operation we must not merge with op1 since that makes side-effects
|
||||
unconditional. So special-case this. */
|
||||
if (!lhs
|
||||
&& ((code == TRUTH_ORIF_EXPR && in0_p)
|
||||
|| (code == TRUTH_ANDIF_EXPR && !in0_p)))
|
||||
return op0;
|
||||
rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
|
||||
|
||||
/* If this is an OR operation, invert both sides; we will invert
|
||||
|
12
gcc/testsuite/c-c++-common/pr96369.c
Normal file
12
gcc/testsuite/c-c++-common/pr96369.c
Normal file
@ -0,0 +1,12 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O" } */
|
||||
|
||||
int main()
|
||||
{
|
||||
const long ONE = 1L;
|
||||
long y = 0L;
|
||||
long x = ((long) (ONE || (y = 1L)) % 8L);
|
||||
if (y != 0)
|
||||
__builtin_abort ();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user