Move out-of-bound case labels warning to the C front end

Steven Bosscher stevenb@suse.de
Tue Jul 20 05:43:00 GMT 2004


On Monday 19 July 2004 22:43, Joseph S. Myers wrote:
> On Mon, 19 Jul 2004, Steven Bosscher wrote:
> > BTW the original reason for adding this code in expr.c was that on
> > the tree-ssa branch we optimize away the default promotion from
> > char to int if the switch testing expression is a char.  This used
> > to trigger an ICE, see PR14730.  With this patch we just kick that
> > out-of-bounds case label out even before gimplifying.
>
> Do all the affected diagnostics already have tests in the testsuite?

No, I need to add them  I did test them of course.


> What happens for case labels that are outside the range of the original
> type but inside the range after conversion to the promoted type (which may
> or may not be the same as the original)?  Warnings may make sense, but the
> labels in such cases still need to be kept.

Those cases are also thrown out.  For example,

/* PR middle-end/14730 */

int t (char i)
{
  switch (i)
    {
    case 1:
    case 7:
    case 10:
    case 14:
    case 9:
    case 256:
      return 0;
    }
  return 1;
}

Here, "case 256:" is thrown out.  That's the whole purpose of the patch.

Why do they have to be kept?  In a proper program, can 'i' ever have
the value "256"?  If so, the bug is in the middle end which removes the 
promotion of 'i' to int, ie. to the middle end the above snippet starts
as 

int t (char i)
{
  int i1 = (int) i;
  switch (i1)
    {
    case 1:
    case 7:
    case 10:
    case 14:
    case 9:
    case 256:
      return 0;
    }
  return 1;
}

and we remove remove the cast in one of the tree optimizers.

Gr.
Steven




More information about the Gcc-patches mailing list