Hi Antoni, a couple of nits and some thoughts.
Antoni Boucher via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > 2020-07-12 Antoni Boucher <boua...@zoho.com> > > gcc/jit/ > PR target/95498 > * jit-playback.c: Add support to handle truncation and extension ^^^ here we usually add the function that gets modified, you can look at other changelog entries as example. > diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c > index 0fddf04da87..4f4a1080c36 100644 > --- a/gcc/jit/jit-playback.c > +++ b/gcc/jit/jit-playback.c > @@ -61,22 +61,39 @@ along with GCC; see the file COPYING3. If not see > > /* gcc::jit::playback::context::build_cast uses the convert.h API, > which in turn requires the frontend to provide a "convert" > - function, apparently as a fallback. > - > - Hence we provide this dummy one, with the requirement that any casts > - are handled before reaching this. */ > + function, apparently as a fallback for casts that can be simplified > + (truncation, extension). */ > extern tree convert (tree type, tree expr); > > tree > convert (tree dst_type, tree expr) > { > - gcc_assert (gcc::jit::active_playback_ctxt); > - gcc::jit::active_playback_ctxt->add_error (NULL, "unhandled conversion"); > - fprintf (stderr, "input expression:\n"); > - debug_tree (expr); > - fprintf (stderr, "requested type:\n"); > - debug_tree (dst_type); > - return error_mark_node; > + tree t_ret = NULL; > + t_ret = targetm.convert_to_type (dst_type, expr); > + if (t_ret) > + return t_ret; ^^^ indent nit > + enum tree_code dst_code = TREE_CODE (dst_type); > + switch (dst_code) > + { > + case INTEGER_TYPE: > + case ENUMERAL_TYPE: > + t_ret = convert_to_integer (dst_type, expr); > + goto maybe_fold; > + > + default: > + gcc_assert (gcc::jit::active_playback_ctxt); > + gcc::jit::active_playback_ctxt->add_error (NULL, "unhandled > conversion"); > + fprintf (stderr, "input expression:\n"); > + debug_tree (expr); > + fprintf (stderr, "requested type:\n"); > + debug_tree (dst_type); > + return error_mark_node; > + > + maybe_fold: > + if (TREE_CODE (t_ret) != C_MAYBE_CONST_EXPR) > + t_ret = fold (t_ret); > + return t_ret; > + } > } Looking at 'convert' at c-convert.c:66 the INTEGER_TYPE case here looks good, but given the set of casts we accept as input I guess we should handle also POINTER_TYPE, BOOLEAN_TYPE and REAL_TYPE. What do you think about? Hope it helps Bests Andrea