Bug 95498 - unhandled conversion
Summary: unhandled conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: jit (show other bugs)
Version: 10.1.0
: P3 normal
Target Milestone: ---
Assignee: David Malcolm
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-03 13:14 UTC by Antoni
Modified: 2021-07-18 14:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Reproducer for the bug (472.45 KB, application/zip)
2020-06-03 13:14 UTC, Antoni
Details
Smaller reproducer for the bug (1.47 KB, text/x-csrc)
2020-07-03 00:58 UTC, Antoni
Details
Minimal reproducer (425 bytes, text/x-csrc)
2020-07-13 09:42 UTC, Alex Coplan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antoni 2020-06-03 13:14:08 UTC
Created attachment 48667 [details]
Reproducer for the bug

Hi.
The attached reproducer fails with the following error:

libgccjit.so: error: unhandled conversion
input expression:
 <integer_cst 0x7fd8f5909f60 type <integer_type 0x7fd8f591e5e8> constant visited 1>
requested type:
 <integer_type 0x7fd8f5a56d20 SI
    size <integer_cst 0x7fd8f5909df8 type <integer_type 0x7fd8f591e0a8 bitsizetype> constant 32>
    unit-size <integer_cst 0x7fd8f5909e10 type <integer_type 0x7fd8f591e000 sizetype> constant 4>
    align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fd8f5a56d20 precision:32 min <integer_cst 0x7fd8f5a48468 -2147483648> max <integer_cst 0x7fd8f5a61c18 2147483647>>
libgccjit.so: error: unhandled conversion
input expression:
 <rshift_expr 0x7fd8f5a58eb0
    type <integer_type 0x7fd8f591e888 public DI
        size <integer_cst 0x7fd8f5909bb8 constant 64>
        unit-size <integer_cst 0x7fd8f5909bd0 constant 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fd8f591e888 precision:64 min <integer_cst 0x7fd8f5909e70 -9223372036854775808> max <integer_cst 0x7fd8f5909ea0 9223372036854775807>
        pointer_to_this <pointer_type 0x7fd8f592edc8>>
    visited
    arg:0 <nop_expr 0x7fd8f5a41ca0 type <integer_type 0x7fd8f591e888>
        visited
        arg:0 <var_decl 0x7fd8f5a5c2d0 returnValue type <integer_type 0x7fd8f591e930>
            visited unsigned DI (null):0:0 size <integer_cst 0x7fd8f5909bb8 64> unit-size <integer_cst 0x7fd8f5909bd0 8>
            align:64 warn_if_not_align:0 context <function_decl 0x7fd8f5947500 _ZN17compiler_builtins3int4udiv12__udivmoddi417h85654ff61d7f0603E> chain <var_decl 0x7fd8f5a5c240 undefined>>>
    arg:1 <bit_and_expr 0x7fd8f5a58e88 type <integer_type 0x7fd8f591e888>
        readonly constant visited
        arg:0 <integer_cst 0x7fd8f5a5b6c0 constant visited 63> arg:1 <integer_cst 0x7fd8f5a5b6c0 63>>>
requested type:
 <integer_type 0x7fd8f5a56d20 SI
    size <integer_cst 0x7fd8f5909df8 type <integer_type 0x7fd8f591e0a8 bitsizetype> constant 32>
    unit-size <integer_cst 0x7fd8f5909e10 type <integer_type 0x7fd8f591e000 sizetype> constant 4>
    align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fd8f5a56d20 precision:32 min <integer_cst 0x7fd8f5a48468 -2147483648> max <integer_cst 0x7fd8f5a61c18 2147483647>>
libgccjit.so: error: unhandled conversion
input expression:
 <error_mark 0x7fd8f5909ba0>
requested type:
 <integer_type 0x7fd8f591e690 public unsigned SI
    size <integer_cst 0x7fd8f5909df8 type <integer_type 0x7fd8f591e0a8 bitsizetype> constant 32>
    unit-size <integer_cst 0x7fd8f5909e10 type <integer_type 0x7fd8f591e000 sizetype> constant 4>
    align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7fd8f591e690 precision:32 min <integer_cst 0x7fd8f5909e28 0> max <integer_cst 0x7fd8f5909de0 4294967295>
    pointer_to_this <pointer_type 0x7fd8f59347e0>>
gcc_jit_result_release: NULL result

Sorry for the size of the reproducer. If you need to, I can try making it smaller.

Thanks to fix this bug.
Comment 1 Antoni 2020-06-06 12:42:52 UTC
I'm trying to create a smaller reproducer by calling gcc_jit_context_dump_to_file, but I don't know where to stop in gdb in order to get the source info.

How did you do it in https://gcc.gnu.org/bugzilla//show_bug.cgi?id=95521 ?
Comment 2 David Malcolm 2020-06-06 17:49:53 UTC
Try putting a breakpoint on add_error (there are a few classes with add_error methods; a sufficiently smart gdb ought to put the breakpoint on all of them).
Comment 3 Antoni 2020-06-06 18:07:05 UTC
(In reply to David Malcolm from comment #2)
> Try putting a breakpoint on add_error (there are a few classes with
> add_error methods; a sufficiently smart gdb ought to put the breakpoint on
> all of them).

I added the call to gcc_jit_context_dump_to_file (ctxt, "/tmp/something.c", 1 /* update_locations */); right after create_code(ctxt) but the parameter loc is NULL when I reach add_error in gdb so that I cannot print the line number.

It was also null when I tried with the reproducer of this issue:
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=95521

Is there anything else to change in the reproducer so that it updates the locations accordingly?
Comment 4 Antoni 2020-07-03 00:58:26 UTC
Created attachment 48829 [details]
Smaller reproducer for the bug

I was able to reduce the size of the reproducer. I attached it.
Comment 5 Alex Coplan 2020-07-13 09:42:43 UTC
Created attachment 48867 [details]
Minimal reproducer

I've done some exhaustive testing of which combinations of casts are allowed. It seems that any program of the following form is rejected with "unhandled conversion":

T f(T x)
{
  return (T)(U)x;
}

where T and U are integral types with U being strictly wider than T.

I've attached a minimal handwritten testcase that reproduces the issue. You should be able to substitute the values passed to t_outer and t_inner for other types and still reproduce the issue, provided that t_outer is a strictly narrower type than t_inner.
Comment 6 Antoni 2020-07-13 10:39:45 UTC
(In reply to Alex Coplan from comment #5)
> Created attachment 48867 [details]
> Minimal reproducer
> 
> I've done some exhaustive testing of which combinations of casts are
> allowed. It seems that any program of the following form is rejected with
> "unhandled conversion":
> 
> T f(T x)
> {
>   return (T)(U)x;
> }
> 
> where T and U are integral types with U being strictly wider than T.
> 
> I've attached a minimal handwritten testcase that reproduces the issue. You
> should be able to substitute the values passed to t_outer and t_inner for
> other types and still reproduce the issue, provided that t_outer is a
> strictly narrower type than t_inner.

Yeah, that's what I figured out.

I sent a patch:
https://gcc.gnu.org/pipermail/jit/2020q3/001228.html

I'd like to have a review of it.
Comment 7 GCC Commits 2021-07-18 14:10:27 UTC
The master branch has been updated by Antoni Boucher <antoyo@gcc.gnu.org>:

https://gcc.gnu.org/g:5cca4131e4aabf70a18e362620ad65a3cebf227a

commit r12-2384-g5cca4131e4aabf70a18e362620ad65a3cebf227a
Author: Antoni Boucher <bouanto@zoho.com>
Date:   Sun Jul 5 19:07:30 2020 -0400

    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>
Comment 8 Antoni 2021-07-18 14:11:50 UTC
Fixed in master.