This is the mail archive of the
mailing list for the GCC project.
Re: optimization of switch statements on i386
"Godmar Back" <email@example.com> writes:
> I increased the number of arms to 5, and retained the "default:
> Now gcc generates a bounds check, followed by a table jump. Good. Now
> how do I get rid of the bounds checks?
> Is there a way to inform gcc that the default branch is never taken?
> (Something along the lines of MSVC's __assert(0)? I had thought
> gcc_unreachable() would do that - but I may be misinformed here.)
gcc_unreachable means nothing special to gcc. If you look at the
resulting code, you will see that it just compiles into a function
call. If you use -Wall you will see that the function was not
declared before being called.
gcc_unreachable is used in the gcc source code itself, but that is
different from being recognized in gcc. It is defined as a macro in
gcc/system.h for use when building gcc itself:
#define gcc_unreachable() (fancy_abort (__FILE__, __LINE__, __FUNCTION__))
There is no way to tell gcc that the default branch is never taken,
although it will omit the default branch if it can prove that the
value is never out of range based on earlier conditional checks.