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 submission for -Wmissing-noreturn


	Here is the final -Wmissing-noreturn patch.  It only gets
activated when asked for.  Ie not in -W -Wall.   Is this okay to install?

		--Kaveh




Tue Oct 13 23:10:58 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-decl.c (warn_missing_noreturn): New global variable.
	(c_decode_option): Check for new flags -W{no-}missing-noreturn.
	(finish_function): Implement missing noreturn warning.

	* c-tree.h (warn_missing_noreturn): Declare extern.

	* invoke.texi: Document new flags.

	* toplev.c (documented_lang_options): Add description.


diff -rup orig/egcs-CVS19981013/gcc/c-decl.c egcs-CVS19981013/gcc/c-decl.c
--- orig/egcs-CVS19981013/gcc/c-decl.c	Tue Oct 13 18:32:16 1998
+++ egcs-CVS19981013/gcc/c-decl.c	Tue Oct 13 22:42:04 1998
@@ -515,6 +515,10 @@ int warn_cast_qual;
 
 int warn_bad_function_cast;
 
+/* Warn about functions which might be candidates for attribute noreturn. */
+
+int warn_missing_noreturn;
+
 /* Warn about traditional constructs whose meanings changed in ANSI C.  */
 
 int warn_traditional;
@@ -728,6 +732,10 @@ c_decode_option (argc, argv)
     warn_bad_function_cast = 1;
   else if (!strcmp (p, "-Wno-bad-function-cast"))
     warn_bad_function_cast = 0;
+  else if (!strcmp (p, "-Wmissing-noreturn"))
+    warn_missing_noreturn = 1;
+  else if (!strcmp (p, "-Wno-missing-noreturn"))
+    warn_missing_noreturn = 0;
   else if (!strcmp (p, "-Wpointer-arith"))
     warn_pointer_arith = 1;
   else if (!strcmp (p, "-Wno-pointer-arith"))
@@ -7191,6 +7199,12 @@ finish_function (nested)
   rest_of_compilation (fndecl);
 
   current_function_returns_null |= can_reach_end;
+
+  if (warn_missing_noreturn
+      && !TREE_THIS_VOLATILE (fndecl)
+      && !current_function_returns_null
+      && !current_function_returns_value)
+    warning ("function does not return, and is not declared `noreturn' ");
 
   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
     warning ("`noreturn' function does return");
diff -rup orig/egcs-CVS19981013/gcc/c-tree.h egcs-CVS19981013/gcc/c-tree.h
--- orig/egcs-CVS19981013/gcc/c-tree.h	Tue Oct 13 18:32:18 1998
+++ egcs-CVS19981013/gcc/c-tree.h	Tue Oct 13 22:40:13 1998
@@ -469,6 +469,10 @@ extern int warn_cast_qual;
 
 extern int warn_bad_function_cast;
 
+/* Warn about functions which might be candidates for attribute noreturn. */
+
+extern int warn_missing_noreturn;
+
 /* Warn about traditional constructs whose meanings changed in ANSI C.  */
 
 extern int warn_traditional;
diff -rup orig/egcs-CVS19981013/gcc/invoke.texi egcs-CVS19981013/gcc/invoke.texi
--- orig/egcs-CVS19981013/gcc/invoke.texi	Tue Oct 13 18:33:17 1998
+++ egcs-CVS19981013/gcc/invoke.texi	Tue Oct 13 23:07:39 1998
@@ -123,7 +123,7 @@ in the following sections.
 -Wimplicit-function-declaration  -Wimport
 -Werror-implicit-function-declaration  -Winline
 -Wlarger-than-@var{len}  -Wlong-long
--Wmain  -Wmissing-declarations
+-Wmain  -Wmissing-declarations  -Wmissing-noreturn
 -Wmissing-prototypes  -Wmultichar  -Wnested-externs  -Wno-import  
 -Wno-non-template-friend -Wold-style-cast  -Woverloaded-virtual  
 -Wparentheses -Wpointer-arith  -Wredundant-decls  -Wreorder  
@@ -1616,6 +1616,9 @@ Warn if a global function is defined wit
 Do so even if the definition itself provides a prototype.
 Use this option to detect global functions that are not declared in
 header files.
+
+@item -Wmissing-noreturn
+Warn about functions which might be candidates for attribute @code{noreturn}.
 
 @item -Wredundant-decls
 Warn if anything is declared more than once in the same scope, even in
diff -rup orig/egcs-CVS19981013/gcc/toplev.c egcs-CVS19981013/gcc/toplev.c
--- orig/egcs-CVS19981013/gcc/toplev.c	Tue Oct 13 22:54:03 1998
+++ egcs-CVS19981013/gcc/toplev.c	Tue Oct 13 22:45:35 1998
@@ -978,6 +978,9 @@ documented_lang_options[] =
   { "-Wbad-function-cast",
     "Warn about casting functions to incompatible types" },
   { "-Wno-bad-function-cast", "" },
+  { "-Wmissing-noreturn",
+    "Warn about functions which might be candidates for attribute noreturn" },
+  { "-Wno-missing-noreturn", "" },
   { "-Wcast-qual", "Warn about casts which discard qualifiers"},
   { "-Wno-cast-qual", "" },
   { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},


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