nonzero-3.C: New testcase.
authorJan Hubicka <hubicka@ucw.cz>
Mon, 13 Apr 2015 14:16:41 +0000 (16:16 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Mon, 13 Apr 2015 14:16:41 +0000 (14:16 +0000)
* g++.dg/tree-ssa/nonzero-3.C: New testcase.
* tree-vrp.c (nonnull_arg_p): THIS pointers and references are non-zero.
(gimple_stmt_nonzero_warnv_p): Reference return values are non-zero.

From-SVN: r222054

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/nonzero-3.C [new file with mode: 0644]
gcc/tree-vrp.c

index 9dcdea6989a673434d8c76ab5717a80056fd2aa8..fe22835447ea63506ac13bf1f08b26f816c236a3 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-12  Jan Hubicka  <hubicka@ucw.cz>
+
+       * tree-vrp.c (nonnull_arg_p): THIS pointers and references are non-zero.
+       (gimple_stmt_nonzero_warnv_p): Reference return values are non-zero.
+
 2015-04-12  Jan Hubicka  <hubicka@ucw.cz>
 
        * ipa-profie.c (ipa_profile): Check number of parameters
index 377f5d989fc4d0a0205cdf75d332276647d5ec00..18ce31ce12fa3c2494e1eef9abe0bc2a0ab9da25 100644 (file)
@@ -1,3 +1,7 @@
+2015-04-12  Jan Hubicka  <hubicka@ucw.cz>
+
+       * g++.dg/tree-ssa/nonzero-3.C: New testcase.
+
 2015-04-13  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/65204
diff --git a/gcc/testsuite/g++.dg/tree-ssa/nonzero-3.C b/gcc/testsuite/g++.dg/tree-ssa/nonzero-3.C
new file mode 100644 (file)
index 0000000..eaad3e6
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1 -fdelete-null-pointer-checks" } */
+struct A {int a;};
+struct B {int b;};
+struct C:A,B {int c;
+  void bar();};
+
+void foo (struct B *);
+void C::bar ()
+{
+  struct C *d = this;
+  foo(this);
+  foo(d);
+}
+void bar (struct C &c)
+{
+  struct C *d = &c;
+  foo(&c);
+  foo(d);
+}
+/* { dg-final { scan-tree-dump-not "if \\(" "vrp1"} } */
+/* { dg-final { cleanup-tree-dump "vrp1" } } */
index 9556ede624744ac5c507711b7a6b8cfb670dd293..23e48b1144d9e1bc1ca898acaa70ecc033141373 100644 (file)
@@ -393,6 +393,17 @@ nonnull_arg_p (const_tree arg)
   if (arg == cfun->static_chain_decl)
     return true;
 
+  /* THIS argument of method is always non-NULL.  */
+  if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
+      && arg == DECL_ARGUMENTS (current_function_decl)
+      && flag_delete_null_pointer_checks)
+    return true;
+
+  /* Values passed by reference are always non-NULL.  */
+  if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE
+      && flag_delete_null_pointer_checks)
+    return true;
+
   fntype = TREE_TYPE (current_function_decl);
   for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
     {
@@ -1216,6 +1227,10 @@ gimple_stmt_nonzero_warnv_p (gimple stmt, bool *strict_overflow_p)
            && DECL_IS_OPERATOR_NEW (fndecl)
            && !TREE_NOTHROW (fndecl))
          return true;
+       /* References are always non-NULL.  */
+       if (flag_delete_null_pointer_checks
+           && TREE_CODE (TREE_TYPE (fndecl)) == REFERENCE_TYPE)
+         return true;
        if (flag_delete_null_pointer_checks && 
            lookup_attribute ("returns_nonnull",
                              TYPE_ATTRIBUTES (gimple_call_fntype (stmt))))