This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch for builtin _Exit


This patch adds builtin _Exit (C99 version of _exit) to GCC - i.e.,
builtin knowledge that it is non-returning.  (Note that the builtin
_exit and _Exit are of limited use - see
<URL:http://gcc.gnu.org/ml/gcc/2000-12/msg00537.html> - but it still
seems logical to include _Exit.)

Bootstrapped with no regressions on i686-pc-linux-gnu.  OK to commit?

gcc/ChangeLog:
2001-01-05  Joseph S. Myers  <jsm28@cam.ac.uk>

	* c-common.c (c_common_nodes_and_builtins): Add _Exit builtin.
	* extend.texi: Document _Exit builtin.

gcc/testsuite/ChangeLog:
2001-01-05  Joseph S. Myers  <jsm28@cam.ac.uk>

	* gcc.c-torture/execute/builtin-noret-1.c: New test.

--- c-common.c.orig	Thu Jan  4 23:31:31 2001
+++ c-common.c	Fri Jan  5 11:20:23 2001
@@ -5526,9 +5526,11 @@ c_common_nodes_and_builtins ()
   builtin_function_2 (NULL_PTR, "alloca", NULL_TREE, ptr_ftype_sizetype,
 		      BUILT_IN_ALLOCA, BUILT_IN_NORMAL, 0, 1, 0);
 #endif
-  /* Declare _exit just to mark it as non-returning.  */
+  /* Declare _exit and _Exit just to mark them as non-returning.  */
   builtin_function_2 (NULL_PTR, "_exit", NULL_TREE, void_ftype_int,
 		      0, NOT_BUILT_IN, 0, 1, 1);
+  builtin_function_2 (NULL_PTR, "_Exit", NULL_TREE, void_ftype_int,
+		      0, NOT_BUILT_IN, 0, !flag_isoc99, 1);

   builtin_function_2 ("__builtin_index", "index",
 		      string_ftype_cstring_int, string_ftype_cstring_int,
--- extend.texi.orig	Thu Jan  4 23:27:43 2001
+++ extend.texi	Fri Jan  5 11:20:23 2001
@@ -3335,6 +3335,7 @@
 @findex cosl
 @findex exit
 @findex _exit
+@findex _Exit
 @findex fabs
 @findex fabsf
 @findex fabsl
@@ -3385,10 +3386,11 @@
 not optimized in a particular case, a call to the library function will
 be emitted.

-The functions @code{abort}, @code{exit}, and @code{_exit} are recognized
-and presumed not to return, but otherwise are not built in.
-@code{_exit} is not recognized in strict ISO C mode (@samp{-ansi},
-@samp{-std=c89} or @samp{-std=c99}).
+The functions @code{abort}, @code{exit}, @code{_Exit} and @code{_exit}
+are recognized and presumed not to return, but otherwise are not built
+in.  @code{_exit} is not recognized in strict ISO C mode (@samp{-ansi},
+@samp{-std=c89} or @samp{-std=c99}).  @code{_Exit} is not recognized in
+strict C89 mode (@samp{-ansi} or @samp{-std=c89}).

 Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp},
 @code{bzero}, @code{index}, @code{rindex} and @code{ffs} may be handled
--- testsuite/gcc.c-torture/execute/builtin-noret-1.c.orig	Fri Sep 11 11:31:59 1998
+++ testsuite/gcc.c-torture/execute/builtin-noret-1.c	Sun Dec 17 18:24:32 2000
@@ -0,0 +1,86 @@
+/* Test for builtin noreturn attributes.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+
+extern void abort (void);
+extern void exit (int);
+#if 0 /* Doesn't work with prototype (bug?).  */
+extern void _exit (int);
+extern void _Exit (int);
+#endif
+
+extern void tabort (void);
+extern void texit (void);
+extern void t_exit (void);
+extern void t_Exit (void);
+
+extern void link_failure (void);
+
+int
+main (void)
+{
+  volatile int i = 0;
+  /* The real test here is that the program links.  */
+  if (i)
+    tabort ();
+  if (i)
+    texit ();
+  if (i)
+    t_exit ();
+  if (i)
+    t_Exit ();
+  exit (0);
+}
+
+void
+tabort (void)
+{
+  abort ();
+  link_failure ();
+}
+
+void
+texit (void)
+{
+  exit (1);
+  link_failure ();
+}
+
+void
+t_exit (void)
+{
+  _exit (1);
+  link_failure ();
+}
+
+/* Some non-Unix libcs might not have _exit.  This version should never
+   get called.  */
+static void
+_exit (int i)
+{
+  abort ();
+}
+
+void
+t_Exit (void)
+{
+  _Exit (1);
+  link_failure ();
+}
+
+/* Some libcs might not have _Exit.  This version should never get called.  */
+static void
+_Exit (int i)
+{
+  abort ();
+}
+
+/* When optimizing, no calls to link_failure should remain.  In any case,
+   link_failure should not be called.  */
+
+#ifndef __OPTIMIZE__
+void
+link_failure (void)
+{
+  abort ();
+}
+#endif

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]