From 5aee8e3f3bebb462781bb8351e6c482ff70f379b Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 8 Nov 2017 13:15:56 -0500 Subject: [PATCH 20/25] {[12/14], approved} C++: introduce null_node_p 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 028f090..cc2a100 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6530,7 +6530,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 = @@ -7864,7 +7864,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 489ebc0..a46dcce 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7445,6 +7445,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; +} + #if CHECKING_P namespace selftest { extern void run_cp_tests (void); 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 b6a8f9e..bfbd23d 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -3230,7 +3230,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 47f267f..872f09d 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 2490cb0..427d259 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4266,7 +4266,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