https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87798

            Bug ID: 87798
           Summary: EH lowering is creating a gimple_switch statement with
                    type-incompatible index and case labels
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amacleod at redhat dot com
  Target Milestone: ---

Created attachment 44925
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44925&action=edit
patch to check for the error condition and trigger a bootstrap failure

This shows up during bootstrap when building the ADA compiler

configuration is x86_64-pc-linux-gnu  with  
--enable-languages=all,ada,go,obj-c++,jit --enable-host-shared

from  https://gcc.gnu.org/ml/gcc/2018-10/msg00248.html :

I am doing some switch analysis and an triggering a failure in ADA when the
gimple_switch_index() is a signed 64 bit value and the case labels are only 32
bit integers.  I would have expected that these needed to be the same
precision?   I don't seem to get this failure anywhere else.

(gdb) p print_gimple_stmt (stderr, sw, 0, 0)

switch (_22) <default: <L9> [67.00%], case 1: <L6> [33.00%]>


(gdb) p gimple_switch_index (sw)
$16 = (tree_node *) 0x7fffee3593f0
(gdb) p print_generic_expr (stderr, $16, 0)
_22
(gdb) p print_generic_expr (stderr, $16->typed.type, 0)
SIGNED_64                                                   << signed 64 bit
index

low is the value of CASE_LOW()

(gdb) p print_generic_expr (stderr, low, 0)
1
(gdb) p low->typed.type
$19 = (tree) 0x7fffefacf5e8
(gdb) p print_generic_expr (stderr, $19, 0)
integer
(gdb) p low->typed.type->type_common.precision
$22 = 32 <<< 32 bit case label
(gdb) p type->type_common.precision
$23 = 64

(gdb) p useless_type_conversion_p ($16->typed.type, $19)
$24 = false
(gdb) p useless_type_conversion_p ($19, $16->typed.type)
$25 = false
(gdb) p types_compatible_p ($19, $16->typed.type)
$26 = false
(gdb) p types_compatible_p ($16->typed.type, $19)
$27 = false

These should at least be type_compatible_p should they not?


The attached patch adds a checking assert in gimple_build_switch() which
verifies that the type of the index and the case labels are compatible.

When added, bootstrap fails here:

/gcc/range2/build/./gcc/xgcc -B/gcc/range2/build/./gcc/
-B/gcc/range2/install/x86_64-pc-linux-gnu/bin/
-B/gcc/range2/install/x86_64-pc-linux-gnu/lib/ -isystem
/gcc/range2/install/x86_64-pc-linux-gnu/include -isystem
/gcc/range2/install/x86_64-pc-linux-gnu/sys-include -c -g -O2 -fpic -W -Wall
-gnatpg -nostdinc a-calcon.adb -o a-calcon.o -wrapper gdb,--args

Breakpoint 1, fancy_abort (file=0x26ba508 "/gcc/range2/gcc/gcc/gimple.c",
line=803, 
    function=0x26bb550 <gimple_build_switch(tree_node*, tree_node*,
vec<tree_node*, va_heap, vl_ptr>)::__FUNCTION__> "gimple_build_switch") at
/gcc/range2/gcc/gcc/diagnostic.c:1560
1560      internal_error ("in %s, at %s:%d", function, trim_filename (file),
line);
Missing separate debuginfos, use: dnf debuginfo-install gmp-6.1.1-1.fc25.x86_64
libgcc-6.4.1-1.fc25.x86_64 libmpc-1.0.2-5.fc24.x86_64
libstdc++-6.4.1-1.fc25.x86_64 mpfr-3.1.5-1.fc25.x86_64
(gdb) where
#0  fancy_abort (file=0x26ba508 "/gcc/range2/gcc/gcc/gimple.c", line=803, 
    function=0x26bb550 <gimple_build_switch(tree_node*, tree_node*,
vec<tree_node*, va_heap, vl_ptr>)::__FUNCTION__> "gimple_build_switch") at
/gcc/range2/gcc/gcc/diagnostic.c:1560
#1  0x00000000011273e4 in gimple_build_switch (index=0x7fffef75f4c8,
default_label=<optimized out>, args=...) at /gcc/range2/gcc/gcc/gimple.c:803
#2  0x000000000167f8ce in lower_eh_dispatch (src=0x7fffef74e478,
stmt=0x7fffef747870) at /gcc/range2/gcc/gcc/tree-eh.c:3775
#3  0x000000000167fcc4 in (anonymous
namespace)::pass_lower_eh_dispatch::execute (this=0x3971d30,
fun=0x7fffef72a580) at /gcc/range2/gcc/gcc/tree-eh.c:3859
#4  0x00000000014464df in execute_one_pass (pass=0x3971d30) at
/gcc/range2/gcc/gcc/passes.c:2446
#5  0x0000000001446884 in execute_pass_list_1 (pass=0x3971d30) at
/gcc/range2/gcc/gcc/passes.c:2535
#6  0x0000000001446914 in execute_pass_list (fn=0x7fffef72a580, pass=0x3971cd0)
at /gcc/range2/gcc/gcc/passes.c:2546
#7  0x0000000000f0e3ad in cgraph_node::expand (this=0x7fffefabcc60) at
/gcc/range2/gcc/gcc/cgraphunit.c:2121
#8  0x0000000000f0ea4c in expand_all_functions () at
/gcc/range2/gcc/gcc/cgraphunit.c:2259
#9  0x0000000000f0f73d in symbol_table::compile (this=0x7fffefabd100) at
/gcc/range2/gcc/gcc/cgraphunit.c:2610
#10 0x0000000000f0fbd8 in symbol_table::finalize_compilation_unit
(this=0x7fffefabd100) at /gcc/range2/gcc/gcc/cgraphunit.c:2788
#11 0x00000000015da4cc in compile_file () at /gcc/range2/gcc/gcc/toplev.c:480
#12 0x00000000015dda0f in do_compile () at /gcc/range2/gcc/gcc/toplev.c:2170


It looks like there are labels for a switch which are subsumed for a try_catch
when lowering:  (from lower_eh_dispatch::tree-eh.c)

        /* Don't generate a switch if there's only a default case.
           This is common in the form of try { A; } catch (...) { B; }.  */
        if (!labels.exists ())
          {
            e = single_succ_edge (src);
            e->flags |= EDGE_FALLTHRU;
          }
        else
          {
            fn = builtin_decl_implicit (BUILT_IN_EH_FILTER);
            x = gimple_build_call (fn, 1, build_int_cst (integer_type_node,
                                                         region_nr));
            filter = create_tmp_var (TREE_TYPE (TREE_TYPE (fn)));
            filter = make_ssa_name (filter, x);
            gimple_call_set_lhs (x, filter);
            gsi_insert_before (&gsi, x, GSI_SAME_STMT);

            /* Turn the default label into a default case.  */
            default_label = build_case_label (NULL, NULL, default_label);
            sort_case_labels (labels);

traps--->>  x = gimple_build_switch (filter, default_label, labels);

The labels coming in are 32 bit, and the result of the call created here is the
64 bit index:

(gdb) p print_generic_expr (stderr, filter->typed.type, 0)
SIGNED_64$

Reply via email to