This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix middle-end/67133, part 2
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 14 Aug 2015 17:27:15 +0200
- Subject: [PATCH] Fix middle-end/67133, part 2
- Authentication-results: sourceware.org; auth=none
This is the second fix for this PR. Here the problem was that we were
accessing arguments that don't exist. We first need to check that the
call stmt has sufficient number of arguments. For details see the PR.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
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.
* gcc.dg/torture/pr67133.c: New test.
diff --git gcc/gimple.c gcc/gimple.c
index cca328a..1bfa8c7 100644
--- gcc/gimple.c
+++ gcc/gimple.c
@@ -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;
+ }
}
}
}
diff --git gcc/testsuite/gcc.dg/torture/pr67133.c gcc/testsuite/gcc.dg/torture/pr67133.c
index e69de29..4eb552e 100644
--- gcc/testsuite/gcc.dg/torture/pr67133.c
+++ gcc/testsuite/gcc.dg/torture/pr67133.c
@@ -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);
+}
Marek