From ddc9105b8cee04070b6b13675bd98a263e4b239d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 8 Nov 2017 13:15:56 -0500
Subject: [PATCH 17/46] 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 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

