re PR middle-end/67133 (ICE at -Os and above on x86_64-linux-gnu in gimple_op, at...
authorMarek Polacek <polacek@redhat.com>
Fri, 14 Aug 2015 16:29:38 +0000 (16:29 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 14 Aug 2015 16:29:38 +0000 (16:29 +0000)
PR middle-end/67133
* gimple.c (infer_nonnull_range_by_attribute): Check that the
nonnull argument position is not outside function arguments.

* gcc.dg/torture/pr67133.c: New test.

From-SVN: r226896

gcc/ChangeLog
gcc/gimple.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr67133.c [new file with mode: 0644]

index afade5dfea4bc946be0bb5a3c9e50ac494f3320f..9d122442b0443af581960703661c86eb38a79f70 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-14  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/67133
+       * gimple.c (infer_nonnull_range_by_attribute): Check that the
+       nonnull argument position is not outside function arguments.
+
 2015-08-14  Matthew Wahab  <matthew.wahab@arm.com>
 
        PR target/67143
index cca328a30e4ec025bfd18789e7b96a1022624e77..1bfa8c7608f367ec04e46cfa61741a85cb6f1ecb 100644 (file)
@@ -2694,10 +2694,13 @@ infer_nonnull_range_by_attribute (gimple stmt, tree op)
          /* Now see if op appears in the nonnull list.  */
          for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
            {
-             int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1;
-             tree arg = gimple_call_arg (stmt, idx);
-             if (operand_equal_p (op, arg, 0))
-               return true;
+             unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1;
+             if (idx < gimple_call_num_args (stmt))
+               {
+                 tree arg = gimple_call_arg (stmt, idx);
+                 if (operand_equal_p (op, arg, 0))
+                   return true;
+               }
            }
        }
     }
index 9a4cd14860feb3be8cf3f2d3acc224dbcbf20773..383fb34dcc5c2d873669c7a11f4731245a68a3d8 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-14  Marek Polacek  <polacek@redhat.com>
+
+       PR middle-end/67133
+       * gcc.dg/torture/pr67133.c: New test.
+
 2015-08-14  Matthew Wahab  <matthew.wahab@arm.com>
            Matthias Klose  <doko@debian.org>
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr67133.c b/gcc/testsuite/gcc.dg/torture/pr67133.c
new file mode 100644 (file)
index 0000000..4eb552e
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fisolate-erroneous-paths-attribute" } */
+
+int printf (const char *, ...);
+int foo (int);
+
+int a, *b, c;
+
+static int
+fn1 ()
+{ 
+  if (a)
+    return (a = 0);
+  for (; a; )
+    a = 0;
+  return 0;
+}
+
+static int
+fn2 (int p)
+{ 
+  fn1 ();
+  c = 0;
+  if (p)
+    printf ("%d", 0);
+  foo (b != &p);
+  return 0;
+}
+
+void
+fn3 ()
+{ 
+  fn2 (0);
+}