diff options
author | David Daney <ddaney@caviumnetworks.com> | 2009-06-11 23:55:45 +0000 |
---|---|---|
committer | David Daney <daney@gcc.gnu.org> | 2009-06-11 23:55:45 +0000 |
commit | 468059bcbb8efdb31fd90369dc2ed122126413fe (patch) | |
tree | 33e26cb48c7e5455995d1edba975d67cf78cad99 /gcc/doc | |
parent | f43def61eaf4f2e1f73c5af6ad806955b8f09949 (diff) | |
download | gcc-468059bcbb8efdb31fd90369dc2ed122126413fe.zip gcc-468059bcbb8efdb31fd90369dc2ed122126413fe.tar.gz gcc-468059bcbb8efdb31fd90369dc2ed122126413fe.tar.bz2 |
re PR c/39252 (Request new feature __builtin_unreachable ())
2009-06-11 David Daney <ddaney@caviumnetworks.com>
PR c/39252
* doc/extend.texi ( __builtin_unreachable): Document new builtin.
* builtins.c (expand_builtin_unreachable): New function.
(expand_builtin): Handle BUILT_IN_UNREACHABLE case.
* builtins.def (BUILT_IN_UNREACHABLE): Add new builtin.
* cfgcleanup.c (try_optimize_cfg): Delete empty blocks with no
successors.
* cfgrtl.c (rtl_verify_flow_info): Handle empty blocks when
searching for missing barriers.
2009-06-11 David Daney <ddaney@caviumnetworks.com>
PR c/39252
* gcc.dg/builtin-unreachable-1.c: New test.
* gcc.dg/builtin-unreachable-2.c: Same.
From-SVN: r148403
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 222d7e0..6817af5 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -6815,6 +6815,61 @@ intentionally executing an illegal instruction) or by calling you should not rely on any particular implementation. @end deftypefn +@deftypefn {Built-in Function} void __builtin_unreachable (void) +If control flow reaches the point of the @code{__builtin_unreachable}, +the program is undefined. It is useful in situations where the +compiler cannot deduce the unreachability of the code. + +One such case is immediately following an @code{asm} statement that +will either never terminate, or one that transfers control elsewhere +and never returns. In this example, without the +@code{__builtin_unreachable}, GCC would issue a warning that control +reaches the end of a non-void function. It would also generate code +to return after the @code{asm}. + +@smallexample +int f (int c, int v) +@{ + if (c) + @{ + return v; + @} + else + @{ + asm("jmp error_handler"); + __builtin_unreachable (); + @} +@} +@end smallexample + +Because the @code{asm} statement unconditionally transfers control out +of the function, control will never reach the end of the function +body. The @code{__builtin_unreachable} is in fact unreachable and +communicates this fact to the compiler. + +Another use for @code{__builtin_unreachable} is following a call a +function that never returns but that is not declared +@code{__attribute__((noreturn))}, as in this example: + +@smallexample +void function_that_never_returns (void); + +int g (int c) +@{ + if (c) + @{ + return 1; + @} + else + @{ + function_that_never_returns (); + __builtin_unreachable (); + @} +@} +@end smallexample + +@end deftypefn + @deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end}) This function is used to flush the processor's instruction cache for the region of memory between @var{begin} inclusive and @var{end} |