public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Reorganize missing noreturn warning
@ 2010-06-01  0:40 Jan Hubicka
  2010-06-09 23:41 ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 2010-06-01  0:40 UTC (permalink / raw)
  To: gcc-patches, rguenther

Hi,
this patch moves noreturn warning code to same infrastructure as const/pure.
This change wording of the warning by "might be possible candidat" to "might be
candidate" and supress the warning when compiler can do full auto detection
(i.e. for static functions, have patch for that in equeue).

I added Wsuggest-attribute=noreturn and kept existing -Wmissing-noreturn as alias.

Bootstrapped/regtested x86_64-linux, OK?

Honza

	* doc/invoke.texi (Wsuggest-attribute): Document.
	(Wmissing-noreturn): Remove.
	* ipa-pure-const.c (warn_function_noreturn): New function.
	* opts.c (decode_options): Set warn_suggest_attribute_noreturn on
	warn_missing_noreturn.
	* common.opt (Wsuggest-attribute=noreturn): New.
	* tree-flow.h (warn_function_noreturn): Declare.
	* tree-cfg.c (execute_warn_function_noreturn): Use
	warn_function_noreturn.
	(gate_warn_function_noreturn): New.
	(pass_warn_function_noreturn): Update.

	* testsuite/gcc.dg/noreturn-7.c: Update.
	* testsuite/gcc.dg/noreturn-4.c: Update.
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 160077)
+++ doc/invoke.texi	(working copy)
@@ -247,7 +247,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wlogical-op -Wlong-long @gol
 -Wmain  -Wmissing-braces  -Wmissing-field-initializers @gol
 -Wmissing-format-attribute  -Wmissing-include-dirs @gol
--Wmissing-noreturn  -Wno-mudflap @gol
+-Wno-mudflap @gol
 -Wno-multichar  -Wnonnull  -Wno-overflow @gol
 -Woverlength-strings  -Wpacked  -Wpacked-bitfield-compat  -Wpadded @gol
 -Wparentheses  -Wpedantic-ms-format -Wno-pedantic-ms-format @gol
@@ -3659,16 +3659,17 @@ attributes currently supported are liste
 @opindex Wno-suggest-attribute=pure
 @opindex Wsuggest-attribute=const
 @opindex Wno-suggest-attribute=const
+@opindex Wsuggest-attribute=noreturn
+@opindex Wno-suggest-attribute=noreturn
 
 Warn about functions which might be candidates for attributes
-@code{pure} or @code{const}.  The compiler only warns for functions
-visible in other compilation units or if it cannot prove that the
-function returns normally. A function returns normally if it doesn't
-contain an infinite loop nor returns abnormally by throwing, calling
-@code{abort()} or trapping.  This analysis requires option
-@option{-fipa-pure-const}, which is enabled by default at @option{-O}
-and higher.  Higher optimization levels improve the accuracy of the
-analysis.
+@code{pure}, @code{const} or @code{noreturn}.  The compiler only warns for
+functions visible in other compilation units or (in the case of @code{pure} and
+@code{const}) if it cannot prove that the function returns normally. A function
+returns normally if it doesn't contain an infinite loop nor returns abnormally
+by throwing, calling @code{abort()} or trapping.  This analysis requires option
+@option{-fipa-pure-const}, which is enabled by default at @option{-O} and
+higher.  Higher optimization levels improve the accuracy of the analysis.
 @end table
 
 @item -Warray-bounds
@@ -4145,16 +4146,6 @@ struct s x = @{ .f = 3, .g = 4 @};
 This warning is included in @option{-Wextra}.  To get other @option{-Wextra}
 warnings without this one, use @samp{-Wextra -Wno-missing-field-initializers}.
 
-@item -Wmissing-noreturn
-@opindex Wmissing-noreturn
-@opindex Wno-missing-noreturn
-Warn about functions which might be candidates for attribute @code{noreturn}.
-Note these are only possible candidates, not absolute ones.  Care should
-be taken to manually verify functions actually do not ever return before
-adding the @code{noreturn} attribute, otherwise subtle code generation
-bugs could be introduced.  You will not get a warning for @code{main} in
-hosted C environments.
-
 @item -Wmissing-format-attribute
 @opindex Wmissing-format-attribute
 @opindex Wno-missing-format-attribute
Index: testsuite/gcc.dg/noreturn-7.c
===================================================================
--- testsuite/gcc.dg/noreturn-7.c	(revision 160077)
+++ testsuite/gcc.dg/noreturn-7.c	(working copy)
@@ -13,7 +13,7 @@ void _exit(int status) __attribute__ ((_
 
 int z = 0;
 
-void g() /* { dg-warning "possible candidate" } */
+void g() /* { dg-warning "might be candidate" } */
 {
   if (++z > 10)
     _exit(0);
@@ -27,14 +27,14 @@ void f()
   f();
 }             /* { dg-bogus "does return" } */
 
-int h() /* { dg-warning "possible candidate" } */
+int h() /* { dg-warning "might be candidate" } */
 {
   if (++z > 10)
     _exit(0);
   return h();
 }             /* { dg-bogus "end of non-void function" } */
 
-int k() /* { dg-warning "possible candidate" } */
+int k() /* { dg-warning "might be candidate" } */
 {
   if (++z > 10)
     _exit(0);
Index: testsuite/gcc.dg/noreturn-4.c
===================================================================
--- testsuite/gcc.dg/noreturn-4.c	(revision 160077)
+++ testsuite/gcc.dg/noreturn-4.c	(working copy)
@@ -4,7 +4,7 @@
 extern void exit (int) __attribute__ ((__noreturn__));
 
 int
-main (void) /* { dg-warning "function might be possible candidate for attribute 'noreturn'" "warn for main" } */
+main (void) /* { dg-warning "function might be candidate for attribute 'noreturn'" "warn for main" } */
 {
   exit (0);
 }
Index: ipa-pure-const.c
===================================================================
--- ipa-pure-const.c	(revision 160079)
+++ ipa-pure-const.c	(working copy)
@@ -177,6 +177,16 @@ warn_function_const (tree decl, bool kno
     = suggest_attribute (OPT_Wsuggest_attribute_const, decl,
 			 known_finite, warned_about, "const");
 }
+
+void
+warn_function_noreturn (tree decl)
+{
+  static struct pointer_set_t *warned_about;
+  if (!lang_hooks.missing_noreturn_ok_p (decl))
+    warned_about 
+      = suggest_attribute (OPT_Wsuggest_attribute_noreturn, decl,
+			   true, warned_about, "noreturn");
+}
 /* Init the function state.  */
 
 static void
Index: opts.c
===================================================================
--- opts.c	(revision 160077)
+++ opts.c	(working copy)
@@ -1062,6 +1062,11 @@ decode_options (unsigned int argc, const
 	       "is disabled.");
       flag_toplevel_reorder = 0;
     }
+
+  /* -Wmissing-noreturn is alias for -Wsuggest-attribute=noreturn.  */
+  if (warn_missing_noreturn)
+    warn_suggest_attribute_noreturn = true;
+    
   /* Unless the user has asked for section anchors, we disable toplevel
      reordering at -O0 to disable transformations that might be surprising
      to end users and to get -fno-toplevel-reorder tested.  */
Index: common.opt
===================================================================
--- common.opt	(revision 160077)
+++ common.opt	(working copy)
@@ -192,6 +192,10 @@ Wsuggest-attribute=pure
 Common Var(warn_suggest_attribute_pure) Warning
 Warn about functions which might be candidates for __attribute__((pure))
 
+Wsuggest-attribute=noreturn
+Common Var(warn_suggest_attribute_noreturn) Warning
+Warn about functions which might be candidates for __attribute__((noreturn))
+
 Wswitch
 Common Var(warn_switch) Warning
 Warn about enumerated switches, with no default, missing a case
Index: tree-flow.h
===================================================================
--- tree-flow.h	(revision 160077)
+++ tree-flow.h	(working copy)
@@ -870,6 +870,9 @@ tree maybe_fold_tmr (tree);
 
 unsigned int execute_free_datastructures (void);
 unsigned int execute_fixup_cfg (void);
+
+/* In ipa-pure-const.c  */
+void warn_function_noreturn (tree);
 
 #include "tree-flow-inline.h"
 
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 160079)
+++ tree-cfg.c	(working copy)
@@ -7247,22 +7256,24 @@ struct gimple_opt_pass pass_warn_functio
 static unsigned int
 execute_warn_function_noreturn (void)
 {
-  if (warn_missing_noreturn
-      && !TREE_THIS_VOLATILE (cfun->decl)
-      && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0
-      && !lang_hooks.missing_noreturn_ok_p (cfun->decl))
-    warning_at (DECL_SOURCE_LOCATION (cfun->decl), OPT_Wmissing_noreturn,
-		"function might be possible candidate "
-		"for attribute %<noreturn%>");
+  if (!TREE_THIS_VOLATILE (current_function_decl)
+      && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0)
+    warn_function_noreturn (current_function_decl);
   return 0;
 }
 
+static bool
+gate_warn_function_noreturn (void)
+{
+  return warn_suggest_attribute_noreturn;
+}
+
 struct gimple_opt_pass pass_warn_function_noreturn =
 {
  {
   GIMPLE_PASS,
   "*warn_function_noreturn",		/* name */
-  NULL,					/* gate */
+  gate_warn_function_noreturn,		/* gate */
   execute_warn_function_noreturn,	/* execute */
   NULL,					/* sub */
   NULL,					/* next */

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-10  1:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-01  0:40 Reorganize missing noreturn warning Jan Hubicka
2010-06-09 23:41 ` Jan Hubicka
2010-06-10  3:53   ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).