Removing bound checks from a switch statement

Jeff Law law@redhat.com
Wed Feb 17 19:00:00 GMT 2010


On 02/17/10 10:55, Henrik Mannerström wrote:
> Hello,
>
> Below is a short program that illustrates my problem. The variable R 
> is of type enum reactions so the compiler should know that it does not 
> need to check it's value in the switch statement on line 10. The 
> assembler output shows that a check is nevertheless inserted. %ebx 
> contains the value or R and .L9 the address of the jump table. 
> Compiled with g++ -S -g -dA -O2 swloop.cc on a X86_64 machine.
>
> Should not the type system ensure that R is within bounds?
No.  The standard allows defining values that are not part of the 
enumeration.

Jeff



More information about the Gcc-help mailing list