re PR tree-optimization/77544 (segfault at -O0 - infinite loop in simplification)
authorRichard Biener <rguenther@suse.de>
Thu, 15 Sep 2016 12:35:13 +0000 (12:35 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 15 Sep 2016 12:35:13 +0000 (12:35 +0000)
2016-09-15  Richard Biener  <rguenther@suse.de>

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
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/torture/pr77544.c [new file with mode: 0644]

index d4ad3c9a9d2cfd178a587a3c33ecc827a96a4a33..019be1a49e43f988f7f01f6a9a870de6ea58f732 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-15  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/77544
+       * fold-const.c (split_tree): Do not split constant ~X.
+
 2016-09-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/77425
index bf177b609e5954ba3b83d9a3df1c4ecea04759da..e5c20528b7eeeb2667e3830d2fcccb38b08d7910 100644 (file)
@@ -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;
 
index 7f0746dedd3904c7684b9668192666ad418f9609..6a7cc9c330638b9825382b108b41828a4c1cda13 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-15  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/77544
+       * c-c++-common/torture/pr77544.c: New testcase.
+
 2016-09-15  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..1d1ce3f
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+struct {
+  long a : 17;
+} b;
+int c, d;
+void e() { b.a = d + c + ~(long)(302806U >> 0); }