From: Jan Hubicka Date: Mon, 13 Apr 2015 14:16:41 +0000 (+0200) Subject: nonzero-3.C: New testcase. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=10706779287de8fffd80b7968baaa1ba45c15a85;p=gcc.git nonzero-3.C: New testcase. * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9dcdea6989a..fe22835447e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-04-12 Jan Hubicka + + * 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 * ipa-profie.c (ipa_profile): Check number of parameters diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 377f5d989fc..18ce31ce12f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-04-12 Jan Hubicka + + * g++.dg/tree-ssa/nonzero-3.C: New testcase. + 2015-04-13 Richard Biener 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 index 00000000000..eaad3e69eb8 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/nonzero-3.C @@ -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" } } */ diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 9556ede6247..23e48b1144d 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -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))))