From 7c05f5c46d5b0db80d65bec5f14a893d0e939c85 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 15 Sep 2016 12:35:13 +0000 Subject: [PATCH] re PR tree-optimization/77544 (segfault at -O0 - infinite loop in simplification) 2016-09-15 Richard Biener PR middle-end/77544 * fold-const.c (split_tree): Do not split constant ~X. * c-c++-common/torture/pr77544.c: New testcase. From-SVN: r240164 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 7 ++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/torture/pr77544.c | 7 +++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/pr77544.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d4ad3c9a9d2..019be1a49e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-09-15 Richard Biener + + PR middle-end/77544 + * fold-const.c (split_tree): Do not split constant ~X. + 2016-09-15 Jakub Jelinek PR rtl-optimization/77425 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bf177b609e5..e5c20528b7e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -837,15 +837,16 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code, var = negate_expr (var); } } + else if (TREE_CONSTANT (in)) + *conp = in; else if (TREE_CODE (in) == BIT_NOT_EXPR && code == PLUS_EXPR) { - /* -X - 1 is folded to ~X, undo that here. */ + /* -X - 1 is folded to ~X, undo that here. Do _not_ do this + when IN is constant. */ *minus_litp = build_one_cst (TREE_TYPE (in)); var = negate_expr (TREE_OPERAND (in, 0)); } - else if (TREE_CONSTANT (in)) - *conp = in; else var = in; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7f0746dedd3..6a7cc9c3306 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-15 Richard Biener + + PR middle-end/77544 + * c-c++-common/torture/pr77544.c: New testcase. + 2016-09-15 Jakub Jelinek PR middle-end/77475 diff --git a/gcc/testsuite/c-c++-common/torture/pr77544.c b/gcc/testsuite/c-c++-common/torture/pr77544.c new file mode 100644 index 00000000000..1d1ce3ff74f --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/pr77544.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ + +struct { + long a : 17; +} b; +int c, d; +void e() { b.a = d + c + ~(long)(302806U >> 0); } -- 2.30.2