Builtin _exit

Joseph S. Myers jsm28@cam.ac.uk
Sun Dec 17 05:59:00 GMT 2000


GCC has a builtin declaration of _exit to mark it as noreturn: (from
c-common.c):

     Declare _exit just to mark it as volatile.  */
  if (! flag_no_builtin && ! flag_no_nonansi_builtin)
    {
#ifndef SMALL_STACK
      temp = builtin_function ("alloca", ptr_ftype_sizetype,
                               BUILT_IN_ALLOCA, BUILT_IN_NORMAL, NULL_PTR);
      /* Suppress error if redefined as a non-function.  */
      DECL_BUILT_IN_NONANSI (temp) = 1;
#endif
      temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS,
                               BUILT_IN_NORMAL, NULL_PTR);
      /* Suppress error if redefined as a non-function.  */
      DECL_BUILT_IN_NONANSI (temp) = 1;
      temp = builtin_function ("_exit", void_ftype_int,
                               0, NOT_BUILT_IN, NULL_PTR);
      TREE_THIS_VOLATILE (temp) = 1;
      TREE_SIDE_EFFECTS (temp) = 1;
      /* Suppress error if redefined as a non-function.  */
      DECL_BUILT_IN_NONANSI (temp) = 1;

This doesn't actually work: (from c-decl.c):

      /* Merge the type qualifiers.  */
      if (TREE_CODE (olddecl) == FUNCTION_DECL
          && DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
          && ! TREE_THIS_VOLATILE (newdecl))
        TREE_THIS_VOLATILE (write_olddecl) = 0;

What's the idea of the combination of the builtin _exit, and this code in
c-decl.c meaning it only applies when _exit is used without a previous
declaration?  This seems to make it useless on systems where GCC is not
the native compiler, with a proper _exit declaration in <unistd.h>, albeit
without the attribute - but it is presumably for systems without
GCC-optimised headers that such default attributes exist.  (This came up
when writing a testcase for these default noreturn attributes.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc mailing list