diff options
author | Antoni Boucher <bouanto@zoho.com> | 2020-07-05 19:07:30 -0400 |
---|---|---|
committer | Antoni Boucher <bouanto@zoho.com> | 2021-07-18 10:09:39 -0400 |
commit | 5cca4131e4aabf70a18e362620ad65a3cebf227a (patch) | |
tree | abaecae41c0b144a5ebca1e451994e82e375caf3 /gcc/jit | |
parent | 853921378bfa149353b4e1c7dde5c02f80072ad7 (diff) | |
download | gcc-5cca4131e4aabf70a18e362620ad65a3cebf227a.zip gcc-5cca4131e4aabf70a18e362620ad65a3cebf227a.tar.gz gcc-5cca4131e4aabf70a18e362620ad65a3cebf227a.tar.bz2 |
libgccjit: Handle truncation and extension for casts [PR95498]
2021-07-18 Antoni Boucher <bouanto@zoho.com>
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 <bouanto@zoho.com>
Diffstat (limited to 'gcc/jit')
-rw-r--r-- | gcc/jit/jit-playback.c | 32 |
1 files changed, 21 insertions, 11 deletions
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 { |