public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Trevor Saunders <tbsaunde@tbsaunde.org>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 1/4] force decls to be allocated through build_decl to initialize them
Date: Wed, 14 Jul 2021 13:27:54 +0200	[thread overview]
Message-ID: <CAFiYyc2HoNeVj3z4Y-EQRky8Xp-HRdY47kWZaPeK6EG=TATAcg@mail.gmail.com> (raw)
In-Reply-To: <20210714081827.12185-1-tbsaunde@tbsaunde.org>

On Wed, Jul 14, 2021 at 10:20 AM Trevor Saunders <tbsaunde@tbsaunde.org> wrote:
>
> 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.
>
> bootstrapped and regtested on x86_64-linux-gnu, ok?

I think all eventually DECL_ARTIFICIAL decls should better use
UNKNOWN_LOCATION instead of input_location.

I'm not sure if I like the (transitional) extra arg to make_node, I suppose
we could hide make_node by declaring it in tree-raw.h or so or by
guarding the decl with NEED_MAKE_NODE.  There's nothing inherently
wrong with calling make_node.  So what I mean with transitional is that
with this change we should simply set the location to UNKNOWN_LOCATION
(aka zero, which it already is), not input_location, in make_node.

Richard.

> Trev
>
> gcc/ChangeLog:
>
>         * cfgexpand.c (avoid_deep_ter_for_debug): Call build_decl not
>         make_node.
>         (expand_gimple_basic_block): Likewise.
>         * ipa-param-manipulation.c (ipa_param_adjustments::modify_call):
>         * Likewise.
>         (ipa_param_body_adjustments::reset_debug_stmts): Likewise.
>         * omp-simd-clone.c (ipa_simd_modify_stmt_ops): Likewise.
>         * stor-layout.c (start_bitfield_representative): Likewise.
>         * tree-inline.c (remap_ssa_name): Likewise.
>         (tree_function_versioning): Likewise.
>         * tree-into-ssa.c (rewrite_debug_stmt_uses): Likewise.
>         * tree-nested.c (lookup_field_for_decl): Likewise.
>         (get_chain_field): Likewise.
>         (create_field_for_decl): Likewise.
>         (get_nl_goto_field): Likewise.
>         (finalize_nesting_tree_1): Likewise.
>         * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
>         * tree-ssa-loop-ivopts.c (remove_unused_ivs): Likewise.
>         * tree-ssa-phiopt.c (spaceship_replacement): Likewise.
>         * tree-ssa-reassoc.c (make_new_ssa_for_def): Likewise.
>         * tree-ssa.c (insert_debug_temp_for_var_def): Likewise.
>         * tree-streamer-in.c (streamer_alloc_tree): Adjust.
>         * tree.c (make_node): Add argument to specify the caller.
>         (build_decl): Move initialization from make_node.
>         * tree.h (enum make_node_caller): new enum.
>         (make_node): Adjust prototype.
>         * varasm.c (make_debug_expr_from_rtl): call build_decl.
>
> gcc/cp/ChangeLog:
>
>         * constraint.cc (build_type_constraint): Call build_decl not make_node.
>         * cp-gimplify.c (cp_genericize_r): Likewise.
>         * parser.c (cp_parser_introduction_list): Likewise.
>         * module.cc (trees_in::start): Adjust.
>
> gcc/fortran/ChangeLog:
>
>         * trans-decl.c (generate_namelist_decl): Call build_decl not make_node.
>         * trans-types.c (gfc_get_array_descr_info): Likewise.
>
> gcc/objc/ChangeLog:
>
>         * objc-act.c (objc_add_property_declaration): Call build_decl not
>         make_node.
>         (maybe_make_artificial_property_decl): Likewise.
>         (objc_build_keyword_decl): Likewise.
>         (build_method_decl): Likewise.
> ---
>  gcc/cfgexpand.c              |  8 ++++----
>  gcc/cp/constraint.cc         |  2 +-
>  gcc/cp/cp-gimplify.c         |  5 +++--
>  gcc/cp/module.cc             |  2 +-
>  gcc/cp/parser.c              |  6 ++----
>  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-streamer-in.c       |  2 +-
>  gcc/tree.c                   | 35 ++++++++++++++++++-----------------
>  gcc/tree.h                   | 13 ++++++++++++-
>  gcc/varasm.c                 | 12 ++++++------
>  23 files changed, 96 insertions(+), 93 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/constraint.cc b/gcc/cp/constraint.cc
> index 4ee5215df50..ae75e5df32b 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -1464,7 +1464,7 @@ build_concept_id (tree expr)
>  tree
>  build_type_constraint (tree decl, tree args, tsubst_flags_t complain)
>  {
> -  tree wildcard = build_nt (WILDCARD_DECL);
> +  tree wildcard = build_decl (input_location, WILDCARD_DECL, nullptr, nullptr);
>    ++processing_template_decl;
>    tree check = build_concept_check (decl, wildcard, args, complain);
>    --processing_template_decl;
> 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/cp/module.cc b/gcc/cp/module.cc
> index ccbde292c22..5c9461ff66b 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -5103,7 +5103,7 @@ trees_in::start (unsigned code)
>           t = build_vl_exp (tree_code (code), ops);
>         }
>        else
> -       t = make_node (tree_code (code));
> +       t = make_node (tree_code (code), MODULE_STREAMER_MKNODE_CALLER);
>        break;
>
>      case INTEGER_CST:
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 93698aa14c9..ea7cdb06789 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -17056,10 +17056,8 @@ cp_parser_introduction_list (cp_parser *parser)
>         break;
>
>        /* Build placeholder. */
> -      tree parm = build_nt (WILDCARD_DECL);
> -      DECL_SOURCE_LOCATION (parm)
> -       = cp_lexer_peek_token (parser->lexer)->location;
> -      DECL_NAME (parm) = identifier;
> +      tree parm = build_decl (cp_lexer_peek_token (parser->lexer)->location,
> +                             WILDCARD_DECL, identifier, nullptr);
>        WILDCARD_PACK_P (parm) = is_pack;
>        vec_safe_push (introduction_vec, parm);
>
> diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
> index a73ce8a3f40..1ec8760037b 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 d715838a046..9ca288df962 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 26b02d7aa95..ac72b7e4de8 100644
> --- a/gcc/ipa-param-manipulation.c
> +++ b/gcc/ipa-param-manipulation.c
> @@ -829,9 +829,9 @@ ipa_param_adjustments::modify_call (cgraph_edge *cs,
>               }
>           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);
> @@ -2055,10 +2055,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 ec20891152b..9fdfe89ed4d 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;
>
> @@ -4890,9 +4888,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;
> @@ -4976,8 +4973,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 f605e763f4a..8d104408156 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);
> @@ -6411,9 +6412,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);
> @@ -6442,10 +6443,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 9ce6214d7e2..533ed1cfd15 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 c6adbbd28a0..025977eeff8 100644
> --- a/gcc/tree-ssa-phiopt.c
> +++ b/gcc/tree-ssa-phiopt.c
> @@ -2430,18 +2430,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-streamer-in.c b/gcc/tree-streamer-in.c
> index e0522bf2ac1..fe95692acc9 100644
> --- a/gcc/tree-streamer-in.c
> +++ b/gcc/tree-streamer-in.c
> @@ -634,7 +634,7 @@ streamer_alloc_tree (class lto_input_block *ib, class data_in *data_in,
>      {
>        /* For all other nodes, materialize the tree with a raw
>          make_node call.  */
> -      result = make_node (code);
> +      result = make_node (code, TREE_STREAMER_MKNODE_CALLER);
>      }
>
>    return result;
> diff --git a/gcc/tree.c b/gcc/tree.c
> index 1aa6e557a04..9c5236a280d 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,17 +1194,9 @@ 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;
> +      gcc_checking_assert (caller == BUILD_DECL_MKNODE_CALLER
> +                          || caller == TREE_STREAMER_MKNODE_CALLER
> +                          || caller == MODULE_STREAMER_MKNODE_CALLER);
>        if (TREE_CODE (t) == DEBUG_EXPR_DECL)
>         DECL_UID (t) = --next_debug_decl_uid;
>        else
> @@ -1212,9 +1204,6 @@ make_node (enum tree_code code MEM_STAT_DECL)
>           DECL_UID (t) = allocate_decl_uid ();
>           SET_DECL_PT_UID (t, -1);
>         }
> -      if (TREE_CODE (t) == LABEL_DECL)
> -       LABEL_DECL_UID (t) = -1;
> -
>        break;
>
>      case tcc_type:
> @@ -5257,10 +5246,22 @@ tree
>  build_decl (location_t loc, enum tree_code code, tree name,
>                  tree type MEM_STAT_DECL)
>  {
> -  tree t;
> +  gcc_checking_assert (TREE_CODE_CLASS (code) == tcc_declaration);
> +  tree t = make_node (code, BUILD_DECL_MKNODE_CALLER PASS_MEM_STAT);
> +  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);
> +    }
>
> -  t = make_node (code PASS_MEM_STAT);
>    DECL_SOURCE_LOCATION (t) = loc;
> +  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..c68997408e2 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -4357,11 +4357,22 @@ 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,
> +  TREE_STREAMER_MKNODE_CALLER,
> +  MODULE_STREAMER_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
>

  parent reply	other threads:[~2021-07-14 11:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  8:18 Trevor Saunders
2021-07-14  8:18 ` [PATCH 2/4] use error_at and warning_at in cfgexpand.c Trevor Saunders
2021-07-14 11:28   ` Richard Biener
2021-07-14  8:18 ` [PATCH 3/4] use diagnostic location in diagnostic_report_current_function Trevor Saunders
2021-07-14 11:29   ` Richard Biener
2021-07-14  8:18 ` [PATCH 4/4] pass location to md_asm_adjust Trevor Saunders
2021-07-14 11:29   ` Richard Biener
2021-07-14 11:27 ` Richard Biener [this message]
2021-07-15  2:24   ` [PATCH 1/4] force decls to be allocated through build_decl to initialize them Trevor Saunders
2021-07-15  8:01     ` Richard Biener
2021-07-16  2:18       ` Trevor Saunders

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='CAFiYyc2HoNeVj3z4Y-EQRky8Xp-HRdY47kWZaPeK6EG=TATAcg@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tbsaunde@tbsaunde.org \
    /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).