switch statement type incompatibilities ?
Richard Biener
richard.guenther@gmail.com
Mon Oct 29 17:30:00 GMT 2018
On October 29, 2018 6:20:25 PM GMT+01:00, Andrew MacLeod <amacleod@redhat.com> wrote:
>What is valid in a switch statement for type compatibility?
>
> I would have expected it to follow what appears to be the gimple
>"standard" of allowing types that pass the
>"useless_type_convserion_p()" test.
>
>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.
They should be the same type (types_ compatible_p), the same conatraint as operands of comparisons. IIRC we have some checking somewhere - eventually it just checks whether the constants fit in the index type.
>(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
>
>
>Is this valid? If so I'll do the promotion myself but this fails
>the
>"is_useless_type_conversion_p ()" test....
>
>Andrew
More information about the Gcc
mailing list