This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: operator new returns nonzero


On Wed, 2 Oct 2013, Jakub Jelinek wrote:

On Mon, Sep 09, 2013 at 10:49:40PM +0200, Marc Glisse wrote:
--- fold-const.c	(revision 202413)
+++ fold-const.c	(working copy)
@@ -16171,21 +16171,31 @@ tree_expr_nonzero_warnv_p (tree t, bool
     case MODIFY_EXPR:
     case BIND_EXPR:
       return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 1),
 					strict_overflow_p);

     case SAVE_EXPR:
       return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 0),
 					strict_overflow_p);

     case CALL_EXPR:
-      return alloca_call_p (t);
+      {
+	tree fn = CALL_EXPR_FN (t);
+	if (TREE_CODE (fn) != ADDR_EXPR) return false;
+	tree fndecl = TREE_OPERAND (fn, 0);
+	if (TREE_CODE (fndecl) != FUNCTION_DECL) return false;
+	if (flag_delete_null_pointer_checks && !flag_check_new
+	    && DECL_IS_OPERATOR_NEW (fndecl)
+	    && !TREE_NOTHROW (fndecl))
+	  return true;
+	return alloca_call_p (t);

Not commenting on what this patch does, but how:
why don't you use tree fndecl = get_callee_fndecl (t);
if (fndecl && ...) return true; instead?

Because I copied the code from alloca_call_p ;-)
get_callee_fndecl does look better indeed.

Perhaps alloca_call_p should use it too.

Thanks, I'll prepare a new patch.

--
Marc Glisse


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