From 5cca4131e4aabf70a18e362620ad65a3cebf227a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 5 Jul 2020 19:07:30 -0400 Subject: libgccjit: Handle truncation and extension for casts [PR95498] 2021-07-18 Antoni Boucher gcc/jit/ PR target/95498 * jit-playback.c (convert): Add support to handle truncation and extension in the convert function. gcc/testsuite/ PR target/95498 * jit.dg/all-non-failing-tests.h: New test. * jit.dg/test-cast.c: New test. Signed-off-by: Antoni Boucher --- gcc/jit/jit-playback.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'gcc/jit/jit-playback.c') diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index c613630..79ac525 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -62,22 +62,32 @@ 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; + switch (TREE_CODE (dst_type)) + { + case INTEGER_TYPE: + case ENUMERAL_TYPE: + return fold (convert_to_integer (dst_type, expr)); + + 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; + } } namespace gcc { -- cgit v1.1