This fixes PR84929.  analyze_siv_subscript_cst_affine chrec_convert()s
chrec_b but doesn't handle the case of that simply wrapping a NOP
around the CHREC.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-03-19  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/84929
        * tree-data-ref.c (analyze_siv_subscript_cst_affine): Guard
        chrec_is_positive against non-chrec arg.

        * gcc.dg/torture/pr84929.c: New testcase.

Index: gcc/tree-data-ref.c
===================================================================
--- gcc/tree-data-ref.c (revision 258641)
+++ gcc/tree-data-ref.c (working copy)
@@ -3015,7 +3017,8 @@ analyze_siv_subscript_cst_affine (tree c
     {
       if (value0 == false)
        {
-         if (!chrec_is_positive (CHREC_RIGHT (chrec_b), &value1))
+         if (TREE_CODE (chrec_b) != POLYNOMIAL_CHREC
+             || !chrec_is_positive (CHREC_RIGHT (chrec_b), &value1))
            {
              if (dump_file && (dump_flags & TDF_DETAILS))
                fprintf (dump_file, "siv test failed: chrec not positive.\n");
@@ -3096,7 +3099,8 @@ analyze_siv_subscript_cst_affine (tree c
        }
       else
        {
-         if (!chrec_is_positive (CHREC_RIGHT (chrec_b), &value2))
+         if (TREE_CODE (chrec_b) != POLYNOMIAL_CHREC
+             || !chrec_is_positive (CHREC_RIGHT (chrec_b), &value2))
            {
              if (dump_file && (dump_flags & TDF_DETAILS))
                fprintf (dump_file, "siv test failed: chrec not positive.\n");
Index: gcc/testsuite/gcc.dg/torture/pr84929.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr84929.c      (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr84929.c      (working copy)
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int32plus } */
+
+int a[4];
+void fn1()
+{
+  __UINT64_TYPE__ b = 7818038963515661296;
+  for (;; b++)
+    a[0xA699ECD2C348A3A0] = a[b];
+}

Reply via email to