i have been trying to change the representation of INT_CSTs so that they
do not carry around the limitation that they can only represent numbers
as large as 2 host_wide_ints (HWI). I have chosen a variable length
implementation that uses an array of HWIs that is just large enough to
hold the specific value. However, the problems that i have hit with
the front ends is that i do math "with in the precision specified by the
type" rather than infinite precision (where infinite is defined to be
the width of two HWIs).
This switch to doing math within the precision causes many test cases to
behave differently. However, I want to know if differently means
"incorrectly" or "I have fixed problems that we have just decided to
live with".
For instance, produces warnings for many (but not all) of the cases at
the bottom of gcc.dg/overflow-warn-1.c. However, there are some test
cases that i find baffling. The most troublesome seems to be
gcc.dg/switch-warn-1.c.
In this test case, the labels of case statements are outside of the
range that can be represented by an unsigned char. However, the
comments in the testcase seem to indicate that it is ok for the value of
the case label to not fit in the range defined by the type of the object
being swiched on.
in my world, this is a problem because the 256 cannot be represented as
an unsigned char and so it looks like an 8 bit 0. This ends up causing
a down stream ice, but that is not the problem. The ice is likely cause
by the fact that there are a large number of places in gcc that think
that they know how to compare ints and some do it one way and some do it
in other ways.
The question is why is having a case label of 256 on a unsigned char
switch legal?
richard sandiford has pointed out to me privately that
for:
unsigned char foo[((1U << 30 << 6) >> 30) + 1];
the array must (and does) have only one element, rather than the
(1 << 6) + 1 you'd get from infinite precision. And in this case
the overflow occurs in the middle of the operation; it's not
something you can fix up after the fact.
Is there something magical about things getting promoted to ints that i
am missing?
kenny