https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63459

--- Comment #5 from Jan Hubicka <hubicka at ucw dot cz> ---
Hi,
does something like this make sense (I also updated the DECL_BY_REFERENCE
check.
We allow to put variable at address NULL with -fno-delete-null-pointer-checks
that IMO can let me to pass it by reference.

Why this is not part of tree_expr_nonzero_p and vrp is not simply calling
it to set up the value ranges?

Honza

Index: tree-vrp.c
===================================================================
--- tree-vrp.c    (revision 215901)
+++ tree-vrp.c    (working copy)
@@ -365,6 +365,18 @@ 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))
+    return true;
+
+  /* Parameters passed by invisible reference are also always non-NULL
+     unsless we explicitly allow symbol to have NULL address, that is
+     permitted by -fno-delete-null-pointer-checks.  */
+  if (DECL_BY_REFERENCE (arg)
+      && flag_delete_null_pointer_checks)
+    return true;
+
   fntype = TREE_TYPE (current_function_decl);
   for (attrs = TYPE_ATTRIBUTES (fntype); attrs; attrs = TREE_CHAIN (attrs))
     {
@@ -772,7 +784,8 @@ get_value_range (const_tree var)
         set_value_range_to_varying (vr);
     }
       else if (TREE_CODE (sym) == RESULT_DECL
-           && DECL_BY_REFERENCE (sym))
+           && DECL_BY_REFERENCE (sym)
+           && flag_delete_null_pointer_checks)
     set_value_range_to_nonnull (vr, TREE_TYPE (sym));
     }

Reply via email to