This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Request of new __attribute__ for switch statements (eliminationof the bounds check)
- From: Ralph Loader <suckfish at ihug dot co dot nz>
- To: Kevin Lawton <kevinlawton2001 at yahoo dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 12 Oct 2002 15:15:35 +1300
- Subject: Re: Request of new __attribute__ for switch statements (eliminationof the bounds check)
- References: <20021011190521.57024.qmail@web80309.mail.yahoo.com>
A more general feature would be a __builtin_not_reached() that informs
the compiler that a particular code path will never be executed and can
be removed at compile time.
Then the example below could be achieved by adding
default: __builtin_not_reached();
to the switch statement.
Ralph.
On Sat, 2002-10-12 at 08:05, Kevin Lawton wrote:
> All,
>
> For implementation of machine simulators, it's quite common
> to have completely populated switch statements on byte values:
>
> unsigned char byte;
>
> switch (byte) {
> case 0:
> case 1:
> ...
> case 255:
> }
>
> But I don't know of any way to tell the compiler to _not_ generate
> a bounds check on the switch variable 'byte'. All of the target
> space is covered.
>
> To solve this, could we add an attribute to switch?
>
> switch (byte) __attribute (( no-bounds-check )) {
> ...
> }
>
> This would also be useful for cases, where it is known that
> all possible targets are covered with case statements, yet
> they don't appear to be fully populated to the compiler
> (it's known only to the programmer that the logic prevents
> certain values).
>
> Thanks,
> -Kevin
>
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
>