This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] Fix PR 30045, ICE in nonnull_arg_p with static chain decl

  The problem here is since the static chain decl is a PARAM_DECL and is
a pointer type, we go through the look in nonnull_arg_p and we found we
cannot find the argument number so we abort.  We could fix it a couple
of different ways:
1) treat static chain decls as non null as they will always be
2) remove the gcc_assert and return false if we don't match the

I choose 1 because it is safer and it can help code generation even
without the nonnull attribute.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.

Andrew Pinski


	* tree-vrp.c (nonnull_arg_p): Treat the static decl as always
	non null.

	* gcc.dg/pr30045.c: New test.

Index: tree-vrp.c
--- tree-vrp.c	(revision 119451)
+++ tree-vrp.c	(working copy)
@@ -102,6 +102,10 @@ nonnull_arg_p (tree arg)
   gcc_assert (TREE_CODE (arg) == PARM_DECL && POINTER_TYPE_P (TREE_TYPE (arg)));
+  /* The static chain decl is always non null.  */
+  if (arg == cfun->static_chain_decl)
+    return true;
   fntype = TREE_TYPE (current_function_decl);
   attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (fntype));
Index: testsuite/gcc.dg/pr30045.c
--- testsuite/gcc.dg/pr30045.c	(revision 0)
+++ testsuite/gcc.dg/pr30045.c	(revision 0)
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-inline" }  */
+int f(int *a)
+  int  __attribute__((nonnull(1))) g(int *b)
+  {
+    int **c = &a;
+    if (b)
+      return *a + **c;
+    return *b;
+  }
+  if (a)
+    return g(a);
+  return 1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]