Discussion:
switch statement type incompatibilities ?
Andrew MacLeod
2018-10-29 17:20:25 UTC
Permalink
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.

(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
Richard Biener
2018-10-29 17:30:10 UTC
Permalink
Post by Andrew MacLeod
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.
Post by Andrew MacLeod
(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
Andrew MacLeod
2018-10-29 17:34:14 UTC
Permalink
Post by Richard Biener
Post by Andrew MacLeod
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.
Fails that test too.

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


now clearly the 32 bit index fit within the 64 bit index, and the
default labels handles the rest..   but I'll look and see if I can find
why this isnt triggering some checking code somewhere...

Andrew
Post by Richard Biener
Post by Andrew MacLeod
(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
Loading...