From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11976 invoked by alias); 10 Nov 2017 21:44:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 11870 invoked by uid 89); 10 Nov 2017 21:44:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=desires, throwing, peculiar, sk:convers X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Nov 2017 21:44:05 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53169624BE; Fri, 10 Nov 2017 21:44:04 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-13.phx2.redhat.com [10.3.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE7E5708F7; Fri, 10 Nov 2017 21:44:01 +0000 (UTC) From: David Malcolm To: Jason Merrill Cc: Nathan Sidwell , Jakub Jelinek , Richard Biener , gcc-patches List , David Malcolm Subject: [PATCH 12/14] C++: introduce null_node_p Date: Fri, 10 Nov 2017 22:11:00 -0000 Message-Id: <1510350329-48956-13-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> References: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00896.txt.bz2 Eschew comparison with null_node in favor of a new null_node_p function, which strips any location wrappers. All of these sites require the node to be non-NULL, with the exception of the one in build_throw, hence the patch adds a test for NULL before the call to non_null_p at that site, rather than putting the test in null_node_p itself. gcc/cp/ChangeLog: * call.c (conversion_null_warnings): Replace comparison with null_node with call to null_node_p. (build_over_call): Likewise. * cp-tree.h (null_node_p): New inline function. * cvt.c (build_expr_type_conversion): Replace comparison with null_node with call to null_node_p. * error.c (args_to_string): Likewise. * except.c (build_throw): Likewise. * typeck.c (cp_build_binary_op): Likewise. --- gcc/cp/call.c | 4 ++-- gcc/cp/cp-tree.h | 7 +++++++ gcc/cp/cvt.c | 2 +- gcc/cp/error.c | 2 +- gcc/cp/except.c | 2 +- gcc/cp/typeck.c | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e4a7f19..a963dd4 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6536,7 +6536,7 @@ static void conversion_null_warnings (tree totype, tree expr, tree fn, int argnum) { /* Issue warnings about peculiar, but valid, uses of NULL. */ - if (expr == null_node && TREE_CODE (totype) != BOOLEAN_TYPE + if (null_node_p (expr) && TREE_CODE (totype) != BOOLEAN_TYPE && ARITHMETIC_TYPE_P (totype)) { source_location loc = @@ -7873,7 +7873,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) func(NULL); } */ - if (arg == null_node + if (null_node_p (arg) && DECL_TEMPLATE_INFO (fn) && cand->template_decl && !(flags & LOOKUP_EXPLICIT_TMPL_ARGS)) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 726b6f5..8735e99 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7440,6 +7440,13 @@ named_decl_hash::equal (const value_type existing, compare_type candidate) return candidate == name; } +inline bool +null_node_p (const_tree expr) +{ + STRIP_ANY_LOCATION_WRAPPER (expr); + return expr == null_node; +} + /* -- end of C++ */ #endif /* ! GCC_CP_TREE_H */ diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 9ce094e..b3a6f69 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1642,7 +1642,7 @@ build_expr_type_conversion (int desires, tree expr, bool complain) tree conv = NULL_TREE; tree winner = NULL_TREE; - if (expr == null_node + if (null_node_p (expr) && (desires & WANT_INT) && !(desires & WANT_NULL)) { diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 2537713..d525103 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -3193,7 +3193,7 @@ args_to_string (tree p, int verbose) reinit_cxx_pp (); for (; p; p = TREE_CHAIN (p)) { - if (TREE_VALUE (p) == null_node) + if (null_node_p (TREE_VALUE (p))) pp_cxx_ws_string (cxx_pp, "NULL"); else dump_type (cxx_pp, error_type (TREE_VALUE (p)), flags); diff --git a/gcc/cp/except.c b/gcc/cp/except.c index ecc8941..30ab23d 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -577,7 +577,7 @@ build_throw (tree exp) return exp; } - if (exp == null_node) + if (exp && null_node_p (exp)) warning (0, "throwing NULL, which has integral, not pointer type"); if (exp != NULL_TREE) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 523e4d3..f139161 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4255,7 +4255,7 @@ cp_build_binary_op (location_t location, } /* Issue warnings about peculiar, but valid, uses of NULL. */ - if ((orig_op0 == null_node || orig_op1 == null_node) + if ((null_node_p (orig_op0) || null_node_p (orig_op1)) /* It's reasonable to use pointer values as operands of && and ||, so NULL is no exception. */ && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR -- 1.8.5.3