On Tue, 9 Nov 2021, Martin Jambor wrote: > Hi, > > On Mon, Nov 08 2021, Prathamesh Kulkarni wrote: > > On Mon, 8 Nov 2021 at 23:24, Martin Jambor <mjam...@suse.cz> wrote: > >> > >> Hi, > >> > >> this patch introduces a helper function build_debug_expr_decl to build > >> DEBUG_EXPR_DECL tree nodes in the most common way and replaces with a > >> call of this function all code pieces which build such a DECL itself > >> and sets its mode to the TYPE_MODE of its type. > >> > >> There still remain 11 instances of open-coded creation of a > >> DEBUG_EXPR_DECL which set the mode of the DECL to something else. It > >> would probably be a good idea to figure out that has any effect and if > >> not, convert them to calls of build_debug_expr_decl too. But this > >> patch deliberately does not introduce any functional changes. > >> > >> Bootstrapped and tested on x86_64-linux, OK for trunk? > >> > >> Thanks, > >> > >> Martin > >> > >> > >> gcc/ChangeLog: > >> > >> 2021-11-08 Martin Jambor <mjam...@suse.cz> > >> > >> * tree.h (build_debug_expr_decl): Declare. > >> * tree.c (build_debug_expr_decl): New function. > >> * cfgexpand.c (avoid_deep_ter_for_debug): Use build_debug_expr_decl > >> instead of building a DEBUG_EXPR_DECL. > >> * ipa-param-manipulation.c > >> (ipa_param_body_adjustments::prepare_debug_expressions): Likewise. > >> * omp-simd-clone.c (ipa_simd_modify_stmt_ops): Likewise. > >> * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise. > >> * tree-ssa-phiopt.c (spaceship_replacement): Likewise. > >> * tree-ssa-reassoc.c (make_new_ssa_for_def): Likewise. > [...] > >> diff --git a/gcc/tree.c b/gcc/tree.c > >> index 7bfd64160f4..845228a055b 100644 > >> --- a/gcc/tree.c > >> +++ b/gcc/tree.c > >> @@ -5280,6 +5280,18 @@ build_decl (location_t loc, enum tree_code code, > >> tree name, > >> return t; > >> } > >> > >> +/* Create and return a DEBUG_EXPR_DECL node of the given TYPE. */ > >> + > >> +tree > >> +build_debug_expr_decl (tree type) > > Hi, sorry to nitpick, but would it be slightly better to use > > const_tree type instead ? > > > > Thanks, > > Prathamesh > >> +{ > >> + tree vexpr = make_node (DEBUG_EXPR_DECL); > >> + DECL_ARTIFICIAL (vexpr) = 1; > >> + TREE_TYPE (vexpr) = type; > > I like the idea but the assignment to TREE_TYPE above could not be done > without discarding the const qualifier somehow. Do we really want to do > that? Do we have some canonical way of doing that? (I searched only > for a minute but did not find any.)
Probably not worth the trouble then (adding some form of const_cast). Richard.