]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/82549 (ICE at -O1 and above: verify_gimple failed)
authorJakub Jelinek <jakub@gcc.gnu.org>
Tue, 17 Oct 2017 14:53:13 +0000 (16:53 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 17 Oct 2017 14:53:13 +0000 (16:53 +0200)
PR tree-optimization/82549
* fold-const.c (optimize_bit_field_compare, fold_truth_andor_1):
Formatting fixes.  Instead of calling make_bit_field_ref with negative
bitpos return 0.

* gcc.c-torture/compile/pr82549.c: New test.

From-SVN: r253818

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr82549.c [new file with mode: 0644]

index e55d99a9b972d44cb62ef7a2f2a22585d06d88b3..07255baa87bfa9e405401076b778392347d273c9 100644 (file)
@@ -1,3 +1,10 @@
+2017-10-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/82549
+       * fold-const.c (optimize_bit_field_compare, fold_truth_andor_1):
+       Formatting fixes.  Instead of calling make_bit_field_ref with negative
+       bitpos return 0.
+
 2017-10-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/82274
index 9ba92b012144f1195c3ef9eaf0259a121abfce5a..508c02d7746b7796a71ae9f230c5bd044da21619 100644 (file)
@@ -3972,21 +3972,20 @@ optimize_bit_field_compare (location_t loc, enum tree_code code,
                      size_int (nbitsize - lbitsize - lbitpos));
 
   if (! const_p)
-    /* If not comparing with constant, just rework the comparison
-       and return.  */
-    return fold_build2_loc (loc, code, compare_type,
-                       fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
-                                    make_bit_field_ref (loc, linner, lhs,
-                                                        unsigned_type,
-                                                        nbitsize, nbitpos,
-                                                        1, lreversep),
-                                    mask),
-                       fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
-                                    make_bit_field_ref (loc, rinner, rhs,
-                                                        unsigned_type,
-                                                        nbitsize, nbitpos,
-                                                        1, rreversep),
-                                    mask));
+    {
+      if (nbitpos < 0)
+       return 0;
+
+      /* If not comparing with constant, just rework the comparison
+        and return.  */
+      tree t1 = make_bit_field_ref (loc, linner, lhs, unsigned_type,
+                                   nbitsize, nbitpos, 1, lreversep);
+      t1 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t1, mask);
+      tree t2 = make_bit_field_ref (loc, rinner, rhs, unsigned_type,
+                                   nbitsize, nbitpos, 1, rreversep);
+      t2 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t2, mask);
+      return fold_build2_loc (loc, code, compare_type, t1, t2);
+    }
 
   /* Otherwise, we are handling the constant case.  See if the constant is too
      big for the field.  Warn and return a tree for 0 (false) if so.  We do
@@ -4017,6 +4016,9 @@ optimize_bit_field_compare (location_t loc, enum tree_code code,
        }
     }
 
+  if (nbitpos < 0)
+    return 0;
+
   /* Single-bit compares should always be against zero.  */
   if (lbitsize == 1 && ! integer_zerop (rhs))
     {
@@ -5891,7 +5893,10 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
         results.  */
       ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask);
       lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask);
-      if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos)
+      if (lnbitsize == rnbitsize
+         && xll_bitpos == xlr_bitpos
+         && lnbitpos >= 0
+         && rnbitpos >= 0)
        {
          lhs = make_bit_field_ref (loc, ll_inner, ll_arg,
                                    lntype, lnbitsize, lnbitpos,
@@ -5915,10 +5920,14 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
         Note that we still must mask the lhs/rhs expressions.  Furthermore,
         the mask must be shifted to account for the shift done by
         make_bit_field_ref.  */
-      if ((ll_bitsize + ll_bitpos == rl_bitpos
-          && lr_bitsize + lr_bitpos == rr_bitpos)
-         || (ll_bitpos == rl_bitpos + rl_bitsize
-             && lr_bitpos == rr_bitpos + rr_bitsize))
+      if (((ll_bitsize + ll_bitpos == rl_bitpos
+           && lr_bitsize + lr_bitpos == rr_bitpos)
+          || (ll_bitpos == rl_bitpos + rl_bitsize
+              && lr_bitpos == rr_bitpos + rr_bitsize))
+         && ll_bitpos >= 0
+         && rl_bitpos >= 0
+         && lr_bitpos >= 0
+         && rr_bitpos >= 0)
        {
          tree type;
 
@@ -5987,6 +5996,9 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
        }
     }
 
+  if (lnbitpos < 0)
+    return 0;
+
   /* Construct the expression we will return.  First get the component
      reference we will make.  Unless the mask is all ones the width of
      that field, perform the mask operation.  Then compare with the
index 332d709643e94959bbc3706e41fe9501c6658871..890a6cd675bdb9abfdb9651817d944be65a52130 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/82549
+       * gcc.c-torture/compile/pr82549.c: New test.
+
 2017-10-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/82274
 
 2017-07-06  Andrew Pinski  <apinski@cavium.com>
 
-       * gcc.target/aarch64/pr71112.c : New Testcase.
+       * gcc.target/aarch64/pr71112.c: New Testcase.
 
 2017-07-04  Release Manager
 
 
        Backport from trunk
        PR fortran/71838
-       * gfortran.dg/submodule_26.f08 : New test.
-       * gfortran.dg/submodule_27.f08 : New test.
+       * gfortran.dg/submodule_26.f08: New test.
+       * gfortran.dg/submodule_27.f08: New test.
 
 2017-04-01  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
        PR fortran/79676
-       * gfortran.dg/submodule_28.f08 : New test.
+       * gfortran.dg/submodule_28.f08: New test.
 
 2017-03-31  Richard Sandiford  <richard.sandiford@arm.com>
 
 
        Backport from trunk
        PR fortran/79434
-       * gfortran.dg/submodule_25.f08 : New test.
+       * gfortran.dg/submodule_25.f08: New test.
 
 2017-03-24  Tom de Vries  <tom@codesourcery.com>
 
 
        Backport from trunk
        PR fortran/71883
-       * gfortran.dg/pr71883.f90 : New test.
+       * gfortran.dg/pr71883.f90: New test.
 
 2016-07-26  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
 2016-02-20  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/69423
-       * gfortran.dg/deferred_character_15.f90 : New test.
+       * gfortran.dg/deferred_character_15.f90: New test.
 
 2016-02-20  Dominique d'Humieres  <dominiq@lps.ens.fr>
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82549.c b/gcc/testsuite/gcc.c-torture/compile/pr82549.c
new file mode 100644 (file)
index 0000000..11525cd
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR tree-optimization/82549 */
+
+int a, b[1];
+
+int
+main ()
+{
+  return !a || b[-2] || b[-2];
+}