[PATCH] PR mid-end/17657: Truncate case ranges to index's type

Zack Weinberg zack@codesourcery.com
Mon Oct 11 01:52:00 GMT 2004


Roger Sayle <roger@eyesopen.com> writes:

> Similar such optimization opportunies occur with things like:
>
>   switch (x & 5)
>   {
>   case 0:  foo(0);  break;
>   case 1:  foo(1);  break;
>   case 2:  foo(2);  break;  /* Unreachable */
>   default: break;
>   }
>
> or
>
>   switch (x | 1)
>   {
>   case 0: foo(0);  break;  /* Unreachable */
>   case 1: foo(1);  break;
>   case 2: foo(2);  break;  /* Unreachable */
>   default: break;
>   }
>
>
> I'd argue that the ability of the middle-end to eliminate the unreachable
> cases above is a valid optimization, and shouldn't result in a diagnostic.
> Not that the middle-end should ever generate warnings, but the code above
> is valid.

For what it's worth, I agree that the code above is valid, should not
produce a diagnostic, and that GCC should strip the unreachable cases.
(I can see deliberately writing such constructs in ifdef-free code,
counting on the compiler to strip the unreachable cases.)

stmt.c doesn't seem like the ideal place for this - unreachable code
stripping should happen as early as possible - but it'll do.

zw



More information about the Gcc-patches mailing list