public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Trevor Saunders <tbsaunde@tbsaunde.org>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 2/4] allow poisoning input_location in ranges it should not be used
Date: Wed, 30 Jun 2021 08:33:30 -0400	[thread overview]
Message-ID: <YNxkmvxDbB7Tmjw6@rag> (raw)
In-Reply-To: <CAFiYyc1pMiBpGs60N=rR+rJQ=yi+81Fx+ux5hqBCYgsMFb8Ctg@mail.gmail.com>

On Wed, Jun 30, 2021 at 11:00:37AM +0200, Richard Biener wrote:
> On Wed, Jun 30, 2021 at 7:37 AM Trevor Saunders <tbsaunde@tbsaunde.org> wrote:
> >
> > This makes it possible to assert if input_location is used during the lifetime
> > of a scope.  This will allow us to find places that currently use it within a
> > function and its callees, or prevent adding uses within the lifetime of a
> > function after all existing uses are removed.
> >
> > bootstrapped and regtested on x86_64-linux-gnu, ok?
> 
> I'm not sure about the general approach but I have comments about
> input_location.
> 
> IMHO a good first step would be to guard the input_location declaration with sth
> like
> 
> #ifndef GCC_NEED_INPUT_LOCATION
> extern location_t input_location;
> #endif

I think that's another reasonable step, my one concern is that it can be
useful to push the usage of input_location, or any other global from the
bottom of the stack to a caller that can provide a better argument
eventually, but first just use the global.  Doing this sort of
refactoring is harder if you need to add files with callers to the
whitelist, and kind of defeats the point of the whitelist.  Consider the
below commit, that is untested, but perhaps I should have included in
this series as somewhat related.

As for this approach being limited to functions that's somewhat true,
but since it effects all functions called while its on the stack, it
would mean once enough infrastructure is fixed, we could add one the
execute method of a pass and nothing in the pass could touch
input_location.  The limit also means that it doesn't get in the way of
the above sort of refactoring, but as it proceeds lower level functions
that now take explicit arguments can be called from contexts that ban
use of input_location.

Trev

From efd04d2df4163dd930f489d9fba1455bfb368114 Mon Sep 17 00:00:00 2001
From: Trevor Saunders <tbsaunde@tbsaunde.org>
Date: Sun, 27 Jun 2021 02:10:26 -0400
Subject: [PATCH] force decls to be allocated through build_decl to initialize
 them
To: gcc-patches@gcc.gnu.org

prior to this commit all calls to build_decl used input_location, even if
temporarily  until build_decl reset the location to something else that it was
told was the proper location.  To avoid using the global we need the caller to
pass in the location it wants, however that's not possible with make_node since
it makes other types of nodes.  So we force all callers who wish to make a decl
to go through build_decl which already takes a location argument.  To avoid
changing behavior this just explicitly passes in input_location to build_decl
for callers of make_node that create a decl, however it would seem in many of
these cases that the location of the decl being coppied might be a better
location.
---
 gcc/cfgexpand.c              |  8 +++---
 gcc/cp/cp-gimplify.c         |  5 ++--
 gcc/fortran/trans-decl.c     |  5 ++--
 gcc/fortran/trans-types.c    |  4 +--
 gcc/ipa-param-manipulation.c |  8 +++---
 gcc/objc/objc-act.c          | 16 +++++-------
 gcc/omp-simd-clone.c         |  4 +--
 gcc/stor-layout.c            |  2 +-
 gcc/tree-inline.c            | 13 +++++-----
 gcc/tree-into-ssa.c          |  4 +--
 gcc/tree-nested.c            | 24 ++++++++----------
 gcc/tree-ssa-ccp.c           |  4 +--
 gcc/tree-ssa-loop-ivopts.c   |  4 +--
 gcc/tree-ssa-phiopt.c        |  8 +++---
 gcc/tree-ssa-reassoc.c       |  4 +--
 gcc/tree-ssa.c               |  4 +--
 gcc/tree.c                   | 49 ++++++++++++++++++------------------
 gcc/tree.h                   |  9 ++++++-
 gcc/varasm.c                 | 12 ++++-----
 19 files changed, 93 insertions(+), 94 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 3edd53c37dc..fea8c837c80 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4342,10 +4342,10 @@ avoid_deep_ter_for_debug (gimple *stmt, int depth)
 	  tree &vexpr = deep_ter_debug_map->get_or_insert (use);
 	  if (vexpr != NULL)
 	    continue;
-	  vexpr = make_node (DEBUG_EXPR_DECL);
+	  vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+			      TREE_TYPE (use));
 	  gimple *def_temp = gimple_build_debug_bind (vexpr, use, g);
 	  DECL_ARTIFICIAL (vexpr) = 1;
-	  TREE_TYPE (vexpr) = TREE_TYPE (use);
 	  SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (use)));
 	  gimple_stmt_iterator gsi = gsi_for_stmt (g);
 	  gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
@@ -5899,14 +5899,14 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
 		       temporary.  */
 		    gimple *debugstmt;
 		    tree value = gimple_assign_rhs_to_tree (def);
-		    tree vexpr = make_node (DEBUG_EXPR_DECL);
 		    rtx val;
 		    machine_mode mode;
 
 		    set_curr_insn_location (gimple_location (def));
 
+		    tree vexpr = build_decl (input_location, DEBUG_EXPR_DECL,
+					     nullptr, TREE_TYPE (value));
 		    DECL_ARTIFICIAL (vexpr) = 1;
-		    TREE_TYPE (vexpr) = TREE_TYPE (value);
 		    if (DECL_P (value))
 		      mode = DECL_MODE (value);
 		    else
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 00b7772fe0d..d537e547169 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1217,8 +1217,9 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
 	      /* Omit from the GENERIC, the back-end can't handle it.  */;
 	    else
 	      {
-		tree using_directive = make_node (IMPORTED_DECL);
-		TREE_TYPE (using_directive) = void_type_node;
+		tree using_directive = build_decl (input_location,
+						   IMPORTED_DECL, nullptr,
+						   void_type_node);
 		DECL_CONTEXT (using_directive) = current_function_decl;
 
 		IMPORTED_DECL_ASSOCIATED_DECL (using_directive) = decl;
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 479ba6fa6ce..b726c2f2bdc 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -5262,10 +5262,9 @@ generate_namelist_decl (gfc_symbol * sym)
       CONSTRUCTOR_APPEND_ELT (nml_decls, NULL_TREE, nml->sym->backend_decl);
     }
 
-  decl = make_node (NAMELIST_DECL);
-  TREE_TYPE (decl) = void_type_node;
+  decl = build_decl (input_location, NAMELIST_DECL, get_identifier (sym->name),
+		     void_type_node);
   NAMELIST_DECL_ASSOCIATED_DECL (decl) = build_constructor (NULL_TREE, nml_decls);
-  DECL_NAME (decl) = get_identifier (sym->name);
   return decl;
 }
 
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 5582e404df9..8b4d5c99665 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3417,9 +3417,9 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
   base_decl = GFC_TYPE_ARRAY_BASE_DECL (type, indirect);
   if (!base_decl)
     {
-      base_decl = make_node (DEBUG_EXPR_DECL);
+      base_decl = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+			      indirect ? build_pointer_type (ptype) : ptype);
       DECL_ARTIFICIAL (base_decl) = 1;
-      TREE_TYPE (base_decl) = indirect ? build_pointer_type (ptype) : ptype;
       SET_DECL_MODE (base_decl, TYPE_MODE (TREE_TYPE (base_decl)));
       GFC_TYPE_ARRAY_BASE_DECL (type, indirect) = base_decl;
     }
diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index f2d91476655..242fa4dee1d 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -834,9 +834,9 @@ ipa_param_adjustments::modify_call (gcall *stmt,
 	      }
 	  if (ddecl == NULL)
 	    {
-	      ddecl = make_node (DEBUG_EXPR_DECL);
+	      ddecl = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				  TREE_TYPE (origin));
 	      DECL_ARTIFICIAL (ddecl) = 1;
-	      TREE_TYPE (ddecl) = TREE_TYPE (origin);
 	      SET_DECL_MODE (ddecl, DECL_MODE (origin));
 
 	      vec_safe_push (*debug_args, origin);
@@ -1883,10 +1883,10 @@ ipa_param_body_adjustments::reset_debug_stmts ()
 	    gcc_assert (is_gimple_debug (stmt));
 	    if (vexpr == NULL && gsip != NULL)
 	      {
-		vexpr = make_node (DEBUG_EXPR_DECL);
+		vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				    TREE_TYPE (name));
 		def_temp = gimple_build_debug_source_bind (vexpr, decl, NULL);
 		DECL_ARTIFICIAL (vexpr) = 1;
-		TREE_TYPE (vexpr) = TREE_TYPE (name);
 		SET_DECL_MODE (vexpr, DECL_MODE (decl));
 		gsi_insert_before (gsip, def_temp, GSI_SAME_STMT);
 	      }
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 8d106a4de26..259ce520143 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -1295,12 +1295,11 @@ objc_add_property_declaration (location_t location, tree decl,
     }
 
   /* Create a PROPERTY_DECL node.  */
-  tree property_decl = make_node (PROPERTY_DECL);
+  tree property_decl = build_decl (DECL_SOURCE_LOCATION (decl), PROPERTY_DECL,
+				   nullptr, TREE_TYPE (decl));
 
   /* Copy the basic information from the original decl.  */
   tree p_type = TREE_TYPE (decl);
-  TREE_TYPE (property_decl) = p_type;
-  DECL_SOURCE_LOCATION (property_decl) = DECL_SOURCE_LOCATION (decl);
   TREE_DEPRECATED (property_decl) = TREE_DEPRECATED (decl);
 
   /* Add property-specific information.  */
@@ -1434,10 +1433,9 @@ maybe_make_artificial_property_decl (tree interface, tree implementation,
       /* Create an artificial property declaration with the
 	 information we collected on the type and getter/setter
 	 names.  */
-      property_decl = make_node (PROPERTY_DECL);
+      property_decl = build_decl (input_location, PROPERTY_DECL, nullptr,
+				  type);
 
-      TREE_TYPE (property_decl) = type;
-      DECL_SOURCE_LOCATION (property_decl) = input_location;
       TREE_DEPRECATED (property_decl) = 0;
       DECL_ARTIFICIAL (property_decl) = 1;
 
@@ -4889,9 +4887,8 @@ objc_build_keyword_decl (tree key_name, tree arg_type,
   /* If no type is specified, default to "id".  */
   arg_type = adjust_type_for_id_default (arg_type);
 
-  keyword_decl = make_node (KEYWORD_DECL);
+  keyword_decl = build_decl (input_location, KEYWORD_DECL, nullptr, arg_type);
 
-  TREE_TYPE (keyword_decl) = arg_type;
   KEYWORD_ARG_NAME (keyword_decl) = arg_name;
   KEYWORD_KEY_NAME (keyword_decl) = key_name;
   DECL_ATTRIBUTES (keyword_decl) = attributes;
@@ -4975,8 +4972,7 @@ build_method_decl (enum tree_code code, tree ret_type, tree selector,
      type of the method.  We may want to change this, and store the
      entire function type in there (eg, it may be used to simplify
      dealing with attributes below).  */
-  method_decl = make_node (code);
-  TREE_TYPE (method_decl) = ret_type;
+  method_decl = build_decl (input_location, code, nullptr, ret_type);
 
   /* If we have a keyword selector, create an identifier_node that
      represents the full selector name (`:' included)...  */
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index b772b7ff520..03189f4c50f 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -910,10 +910,10 @@ ipa_simd_modify_stmt_ops (tree *tp, int *walk_subtrees, void *data)
       gimple *stmt;
       if (is_gimple_debug (info->stmt))
 	{
-	  tree vexpr = make_node (DEBUG_EXPR_DECL);
+	  tree vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				   TREE_TYPE (repl));
 	  stmt = gimple_build_debug_source_bind (vexpr, repl, NULL);
 	  DECL_ARTIFICIAL (vexpr) = 1;
-	  TREE_TYPE (vexpr) = TREE_TYPE (repl);
 	  SET_DECL_MODE (vexpr, TYPE_MODE (TREE_TYPE (repl)));
 	  repl = vexpr;
 	}
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 242452f2acf..7811fc6c302 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2024,7 +2024,7 @@ finalize_type_size (tree type)
 static tree
 start_bitfield_representative (tree field)
 {
-  tree repr = make_node (FIELD_DECL);
+  tree repr = build_decl (input_location, FIELD_DECL, nullptr, nullptr);
   DECL_FIELD_OFFSET (repr) = DECL_FIELD_OFFSET (field);
   /* Force the representative to begin at a BITS_PER_UNIT aligned
      boundary - C++ may use tail-padding of a base object to
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 9e041ca4d56..0204ce20282 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -193,7 +193,6 @@ remap_ssa_name (tree name, copy_body_data *id)
 	  && id->entry_bb == NULL
 	  && single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
 	{
-	  tree vexpr = make_node (DEBUG_EXPR_DECL);
 	  gimple *def_temp;
 	  gimple_stmt_iterator gsi;
 	  tree val = SSA_NAME_VAR (name);
@@ -210,9 +209,11 @@ remap_ssa_name (tree name, copy_body_data *id)
 	  n = id->decl_map->get (val);
 	  if (n && TREE_CODE (*n) == DEBUG_EXPR_DECL)
 	    return *n;
+
+	  tree vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				   TREE_TYPE (name));
 	  def_temp = gimple_build_debug_source_bind (vexpr, val, NULL);
 	  DECL_ARTIFICIAL (vexpr) = 1;
-	  TREE_TYPE (vexpr) = TREE_TYPE (name);
 	  SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name)));
 	  gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
 	  gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
@@ -6494,9 +6495,9 @@ tree_function_versioning (tree old_decl, tree new_decl,
 	      debug_args = decl_debug_args_insert (new_decl);
 	      len = vec_safe_length (*debug_args);
 	    }
-	  ddecl = make_node (DEBUG_EXPR_DECL);
+	  ddecl = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+			      TREE_TYPE (parm));
 	  DECL_ARTIFICIAL (ddecl) = 1;
-	  TREE_TYPE (ddecl) = TREE_TYPE (parm);
 	  SET_DECL_MODE (ddecl, DECL_MODE (parm));
 	  vec_safe_push (*debug_args, DECL_ORIGIN (parm));
 	  vec_safe_push (*debug_args, ddecl);
@@ -6525,10 +6526,10 @@ tree_function_versioning (tree old_decl, tree new_decl,
 		var = TREE_CHAIN (var);
 	      if (var == NULL_TREE)
 		break;
-	      vexpr = make_node (DEBUG_EXPR_DECL);
 	      tree parm = (**debug_args)[i];
+	      vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				  TREE_TYPE (parm));
 	      DECL_ARTIFICIAL (vexpr) = 1;
-	      TREE_TYPE (vexpr) = TREE_TYPE (parm);
 	      SET_DECL_MODE (vexpr, DECL_MODE (parm));
 	      def_temp = gimple_build_debug_bind (var, vexpr, NULL);
 	      gsi_insert_before (&cgsi, def_temp, GSI_NEW_STMT);
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index 8045e34df26..f9933305957 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -1284,10 +1284,10 @@ rewrite_debug_stmt_uses (gimple *stmt)
 	      if (def == NULL_TREE)
 		{
 		  gimple *def_temp;
-		  def = make_node (DEBUG_EXPR_DECL);
+		  def = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				    TREE_TYPE (var));
 		  def_temp = gimple_build_debug_source_bind (def, var, NULL);
 		  DECL_ARTIFICIAL (def) = 1;
-		  TREE_TYPE (def) = TREE_TYPE (var);
 		  SET_DECL_MODE (def, DECL_MODE (var));
 		  gsi =
 		 gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c
index 9edd922a303..37e229477ec 100644
--- a/gcc/tree-nested.c
+++ b/gcc/tree-nested.c
@@ -394,8 +394,8 @@ lookup_field_for_decl (struct nesting_info *info, tree decl,
   if (!*slot)
     {
       tree type = get_frame_type (info);
-      tree field = make_node (FIELD_DECL);
-      DECL_NAME (field) = DECL_NAME (decl);
+      tree field = build_decl (input_location, FIELD_DECL, DECL_NAME (decl),
+			       nullptr);
 
       if (use_pointer_in_frame (decl))
 	{
@@ -510,9 +510,8 @@ get_chain_field (struct nesting_info *info)
     {
       tree type = build_pointer_type (get_frame_type (info->outer));
 
-      field = make_node (FIELD_DECL);
-      DECL_NAME (field) = get_identifier ("__chain");
-      TREE_TYPE (field) = type;
+      field = build_decl (input_location, FIELD_DECL,
+			  get_identifier ("__chain"), type);
       SET_DECL_ALIGN (field, TYPE_ALIGN (type));
       DECL_NONADDRESSABLE_P (field) = 1;
 
@@ -694,9 +693,7 @@ lookup_element_for_decl (struct nesting_info *info, tree decl,
 static tree
 create_field_for_decl (struct nesting_info *info, tree decl, tree type)
 {
-  tree field = make_node (FIELD_DECL);
-  DECL_NAME (field) = DECL_NAME (decl);
-  TREE_TYPE (field) = type;
+  tree field = build_decl (input_location, FIELD_DECL, DECL_NAME (decl), type);
   TREE_ADDRESSABLE (field) = 1;
   insert_field_into_struct (get_frame_type (info), field);
   return field;
@@ -783,9 +780,8 @@ get_nl_goto_field (struct nesting_info *info)
       type = build_array_type
 	(type, build_index_type (size_int (size)));
 
-      field = make_node (FIELD_DECL);
-      DECL_NAME (field) = get_identifier ("__nl_goto_buf");
-      TREE_TYPE (field) = type;
+      field = build_decl (input_location, FIELD_DECL,
+			  get_identifier ("__nl_goto_buf"), type);
       SET_DECL_ALIGN (field, TYPE_ALIGN (type));
       TREE_ADDRESSABLE (field) = 1;
 
@@ -3378,10 +3374,10 @@ finalize_nesting_tree_1 (struct nesting_info *root)
       /* Create a field in the FRAME record to hold the frame base address for
 	 this stack frame.  Since it will be used only by the debugger, put it
 	 at the end of the record in order not to shift all other offsets.  */
-      tree fb_decl = make_node (FIELD_DECL);
+      tree fb_decl = build_decl (input_location, FIELD_DECL,
+				 get_identifier ("FRAME_BASE.PARENT"),
+				 ptr_type_node);
 
-      DECL_NAME (fb_decl) = get_identifier ("FRAME_BASE.PARENT");
-      TREE_TYPE (fb_decl) = ptr_type_node;
       TREE_ADDRESSABLE (fb_decl) = 1;
       DECL_CONTEXT (fb_decl) = root->frame_type;
       TYPE_FIELDS (root->frame_type) = chainon (TYPE_FIELDS (root->frame_type),
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 42585412325..dc6f412c02d 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -3067,9 +3067,9 @@ optimize_atomic_bit_test_and (gimple_stmt_iterator *gsip,
       tree temp = NULL_TREE;
       if (!throws || after || single_pred_p (e->dest))
 	{
-	  temp = make_node (DEBUG_EXPR_DECL);
+	  temp = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+			     TREE_TYPE (lhs));
 	  DECL_ARTIFICIAL (temp) = 1;
-	  TREE_TYPE (temp) = TREE_TYPE (lhs);
 	  SET_DECL_MODE (temp, TYPE_MODE (TREE_TYPE (lhs)));
 	  tree t = build2 (LSHIFT_EXPR, TREE_TYPE (lhs), new_lhs, bit);
 	  g = gimple_build_debug_bind (temp, t, g);
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 12a8a49a307..953b3d0b2f1 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -7677,9 +7677,9 @@ remove_unused_ivs (struct ivopts_data *data, bitmap toremove)
 	      comp = unshare_expr (comp);
 	      if (count > 1)
 		{
-		  tree vexpr = make_node (DEBUG_EXPR_DECL);
+		  tree vexpr = build_decl (input_location, DEBUG_EXPR_DECL,
+					   nullptr, TREE_TYPE (comp));
 		  DECL_ARTIFICIAL (vexpr) = 1;
-		  TREE_TYPE (vexpr) = TREE_TYPE (comp);
 		  if (SSA_NAME_VAR (def))
 		    SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (def)));
 		  else
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 1777bff2f7c..25589716a11 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -2302,18 +2302,18 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb,
 	     all floating point numbers should be comparable.  */
 	  gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (phi));
 	  tree type = TREE_TYPE (phires);
-	  tree temp1 = make_node (DEBUG_EXPR_DECL);
+	  tree temp1 = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				   type);
 	  DECL_ARTIFICIAL (temp1) = 1;
-	  TREE_TYPE (temp1) = type;
 	  SET_DECL_MODE (temp1, TYPE_MODE (type));
 	  tree t = build2 (one_cmp, boolean_type_node, lhs1, rhs2);
 	  t = build3 (COND_EXPR, type, t, build_one_cst (type),
 		      build_int_cst (type, -1));
 	  gimple *g = gimple_build_debug_bind (temp1, t, phi);
 	  gsi_insert_before (&gsi, g, GSI_SAME_STMT);
-	  tree temp2 = make_node (DEBUG_EXPR_DECL);
+	  tree temp2 = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				   type);
 	  DECL_ARTIFICIAL (temp2) = 1;
-	  TREE_TYPE (temp2) = type;
 	  SET_DECL_MODE (temp2, TYPE_MODE (type));
 	  t = build2 (EQ_EXPR, boolean_type_node, lhs1, rhs2);
 	  t = build3 (COND_EXPR, type, t, build_zero_cst (type), temp1);
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 2dd4435b981..48f6117a731 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -1214,14 +1214,14 @@ make_new_ssa_for_def (gimple *stmt, enum tree_code opcode, tree op)
 	{
 	  if (new_debug_lhs == NULL_TREE)
 	    {
-	      new_debug_lhs = make_node (DEBUG_EXPR_DECL);
+	      new_debug_lhs = build_decl (input_location, DEBUG_EXPR_DECL,
+					  nullptr, TREE_TYPE (lhs));
 	      gdebug *def_temp
 		= gimple_build_debug_bind (new_debug_lhs,
 					   build2 (opcode, TREE_TYPE (lhs),
 						   new_lhs, op),
 					   stmt);
 	      DECL_ARTIFICIAL (new_debug_lhs) = 1;
-	      TREE_TYPE (new_debug_lhs) = TREE_TYPE (lhs);
 	      SET_DECL_MODE (new_debug_lhs, TYPE_MODE (TREE_TYPE (lhs)));
 	      gimple_set_uid (def_temp, gimple_uid (stmt));
 	      gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 4cc400d3c2e..83caadb37c8 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -434,14 +434,14 @@ insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
       else
 	{
 	  gdebug *def_temp;
-	  tree vexpr = make_node (DEBUG_EXPR_DECL);
+	  tree vexpr = build_decl (input_location, DEBUG_EXPR_DECL, nullptr,
+				   TREE_TYPE (value));
 
 	  def_temp = gimple_build_debug_bind (vexpr,
 					      unshare_expr (value),
 					      def_stmt);
 
 	  DECL_ARTIFICIAL (vexpr) = 1;
-	  TREE_TYPE (vexpr) = TREE_TYPE (value);
 	  if (DECL_P (value))
 	    SET_DECL_MODE (vexpr, DECL_MODE (value));
 	  else
diff --git a/gcc/tree.c b/gcc/tree.c
index 1aa6e557a04..a90097a51c6 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1175,7 +1175,7 @@ allocate_decl_uid (void)
    Achoo!  I got a code in the node.  */
 
 tree
-make_node (enum tree_code code MEM_STAT_DECL)
+make_node (enum tree_code code, make_node_caller caller MEM_STAT_DECL)
 {
   tree t;
   enum tree_code_class type = TREE_CODE_CLASS (code);
@@ -1194,27 +1194,7 @@ make_node (enum tree_code code MEM_STAT_DECL)
       break;
 
     case tcc_declaration:
-      if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
-	{
-	  if (code == FUNCTION_DECL)
-	    {
-	      SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
-	      SET_DECL_MODE (t, FUNCTION_MODE);
-	    }
-	  else
-	    SET_DECL_ALIGN (t, 1);
-	}
-      DECL_SOURCE_LOCATION (t) = input_location;
-      if (TREE_CODE (t) == DEBUG_EXPR_DECL)
-	DECL_UID (t) = --next_debug_decl_uid;
-      else
-	{
-	  DECL_UID (t) = allocate_decl_uid ();
-	  SET_DECL_PT_UID (t, -1);
-	}
-      if (TREE_CODE (t) == LABEL_DECL)
-	LABEL_DECL_UID (t) = -1;
-
+      gcc_assert (caller == BUILD_DECL_MKNODE_CALLER);
       break;
 
     case tcc_type:
@@ -5257,10 +5237,29 @@ tree
 build_decl (location_t loc, enum tree_code code, tree name,
     		 tree type MEM_STAT_DECL)
 {
-  tree t;
-
-  t = make_node (code PASS_MEM_STAT);
+  tree t = make_node (code, BUILD_DECL_MKNODE_CALLER PASS_MEM_STAT);
   DECL_SOURCE_LOCATION (t) = loc;
+  if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
+    {
+      if (code == FUNCTION_DECL)
+	{
+	  SET_DECL_ALIGN (t, FUNCTION_ALIGNMENT (FUNCTION_BOUNDARY));
+	  SET_DECL_MODE (t, FUNCTION_MODE);
+	}
+      else
+	SET_DECL_ALIGN (t, 1);
+    }
+
+  if (TREE_CODE (t) == DEBUG_EXPR_DECL)
+    DECL_UID (t) = --next_debug_decl_uid;
+  else
+    {
+      DECL_UID (t) = allocate_decl_uid ();
+      SET_DECL_PT_UID (t, -1);
+    }
+
+  if (TREE_CODE (t) == LABEL_DECL)
+    LABEL_DECL_UID (t) = -1;
 
 /*  if (type == error_mark_node)
     type = integer_type_node; */
diff --git a/gcc/tree.h b/gcc/tree.h
index 8bdf16d8b4a..86dd32354f2 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4357,11 +4357,18 @@ extern size_t tree_code_size (enum tree_code);
 /* Allocate and return a new UID from the DECL_UID namespace.  */
 extern int allocate_decl_uid (void);
 
+/* expected callers of make_node.  */
+enum make_node_caller
+{
+  UNKNOWN_MKNODE_CALLER,
+  BUILD_DECL_MKNODE_CALLER
+};
+
 /* Lowest level primitive for allocating a node.
    The TREE_CODE is the only argument.  Contents are initialized
    to zero except for a few of the common fields.  */
 
-extern tree make_node (enum tree_code CXX_MEM_STAT_INFO);
+extern tree make_node (enum tree_code, enum make_node_caller caller = UNKNOWN_MKNODE_CALLER CXX_MEM_STAT_INFO);
 
 /* Free tree node.  */
 
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 53cf6dea3f3..fa6799e48fb 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -8229,21 +8229,21 @@ output_file_directive (FILE *asm_file, const char *input_name)
 rtx
 make_debug_expr_from_rtl (const_rtx exp)
 {
-  tree ddecl = make_node (DEBUG_EXPR_DECL), type;
+  tree type;
   machine_mode mode = GET_MODE (exp);
   rtx dval;
 
-  DECL_ARTIFICIAL (ddecl) = 1;
   if (REG_P (exp) && REG_EXPR (exp))
     type = TREE_TYPE (REG_EXPR (exp));
   else if (MEM_P (exp) && MEM_EXPR (exp))
     type = TREE_TYPE (MEM_EXPR (exp));
   else
     type = NULL_TREE;
-  if (type && TYPE_MODE (type) == mode)
-    TREE_TYPE (ddecl) = type;
-  else
-    TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
+  if (!type || TYPE_MODE (type) != mode)
+    type = lang_hooks.types.type_for_mode (mode, 1);
+
+  tree ddecl = build_decl (input_location, DEBUG_EXPR_DECL, nullptr, type);
+  DECL_ARTIFICIAL (ddecl) = 1;
   SET_DECL_MODE (ddecl, mode);
   dval = gen_rtx_DEBUG_EXPR (mode);
   DEBUG_EXPR_TREE_DECL (dval) = ddecl;
-- 
2.20.1


  reply	other threads:[~2021-06-30 12:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  5:35 [PATCH 1/4] add utility to poison globals that " Trevor Saunders
2021-06-30  5:35 ` [PATCH 2/4] allow poisoning input_location in ranges it " Trevor Saunders
2021-06-30  9:00   ` Richard Biener
2021-06-30 12:33     ` Trevor Saunders [this message]
2021-06-30 19:09       ` Richard Biener
2021-07-01 10:23         ` Trevor Saunders
2021-07-01 12:48           ` Richard Biener
2021-06-30 15:13   ` David Malcolm
2021-06-30 19:34     ` Jason Merrill
2021-07-01 10:16     ` Trevor Saunders
2021-07-01 12:53       ` Richard Biener
2021-07-01 15:40         ` David Malcolm
2021-07-01 16:04           ` David Malcolm
2021-07-01 21:51             ` [committed] input.c: move file caching globals to a new file_cache class David Malcolm
2021-07-11 16:58               ` Lewis Hyatt
2021-07-14 22:53                 ` David Malcolm
2021-07-02  0:44           ` [PATCH 2/4] allow poisoning input_location in ranges it should not be used Trevor Saunders
2021-07-02 15:46       ` Jason Merrill
2021-07-02 23:23         ` Trevor Saunders
2021-07-02 19:20   ` Martin Sebor
2021-07-02 23:47     ` Trevor Saunders
2021-07-06 20:53       ` Martin Sebor
2021-06-30  5:35 ` [PATCH 3/4] allow poisoning cfun Trevor Saunders
2021-06-30  5:35 ` [PATCH 4/4] poison input_location and cfun in one spot Trevor Saunders
2021-06-30  9:02   ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YNxkmvxDbB7Tmjw6@rag \
    --to=tbsaunde@tbsaunde.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).