* doc/invoke.texi (Wsuggest-attribute): Document.
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jun 2010 12:29:53 +0000 (12:29 +0000)
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Jun 2010 12:29:53 +0000 (12:29 +0000)
(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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160606 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/common.opt
gcc/doc/invoke.texi
gcc/ipa-pure-const.c
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/noreturn-4.c
gcc/testsuite/gcc.dg/noreturn-7.c
gcc/tree-cfg.c
gcc/tree-cfgcleanup.c
gcc/tree-flow.h

index 742950c..59f6939 100644 (file)
@@ -1,3 +1,17 @@
+2010-06-11  Jan Hubicka  <jh@suse.cz>
+
+       * 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.
+
 2010-06-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * c-typeck.c (handle_warn_cast_qual): Add loc
index a961582..f001e02 100644 (file)
@@ -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 777c384..3519ead 100644 (file)
@@ -248,7 +248,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
@@ -3667,16 +3667,17 @@ attributes currently supported are listed below.
 @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
@@ -4153,16 +4154,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 766c8fc..da8d442 100644 (file)
@@ -177,6 +177,16 @@ warn_function_const (tree decl, bool known_finite)
     = 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
@@ -1514,11 +1524,7 @@ local_pure_const (void)
   if (!skip && !TREE_THIS_VOLATILE (current_function_decl)
       && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0)
     {
-      if (warn_missing_noreturn
-         && !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%>");
+      warn_function_noreturn (cfun->decl);
       if (dump_file)
         fprintf (dump_file, "Function found to be noreturn: %s\n",
                 lang_hooks.decl_printable_name (current_function_decl, 2));
index 8699ec3..e304ce5 100644 (file)
@@ -1062,6 +1062,11 @@ decode_options (unsigned int argc, const char **argv)
               "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 e7eae08..372d595 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-11  Jan Hubicka  <jh@suse.cz>
+
+       * testsuite/gcc.dg/noreturn-7.c: Update.
+       * testsuite/gcc.dg/noreturn-4.c: Update.
+
 2010-06-10  Dodji Seketeli  <dodji@redhat.com>
 
        Fix MIPS bootstrap
index bcc29da..6fe1447 100644 (file)
@@ -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 1913be1..fd2be2d 100644 (file)
@@ -13,7 +13,7 @@ void _exit(int status) __attribute__ ((__noreturn__));
 
 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 f46556f..4064794 100644 (file)
@@ -7256,22 +7256,24 @@ struct gimple_opt_pass pass_warn_function_return =
 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 */
index fc2141f..8dec8c7 100644 (file)
@@ -568,9 +568,23 @@ fixup_noreturn_call (gimple stmt)
           imm_use_iterator iter;
          gimple use_stmt;
 
+         /* All statements using the OP are unreachable or PHI
+            statements where the edge correspoing to OP use is unreachable.
+            We need to remove all normal statements so fixup_cfg will not
+            try to update them and keep all PHIs but remove use of the SSA
+            name or verifier will complain.  */
           FOR_EACH_IMM_USE_STMT (use_stmt, iter, op)
-           FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
-             SET_USE (use_p, error_mark_node);
+           {
+             if (gimple_code (use_stmt) == GIMPLE_PHI)
+               FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+                 SET_USE (use_p, error_mark_node);
+             else
+               {
+                 gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
+                 gsi_remove (&gsi, true);
+               }
+           }
+         release_ssa_name (op);
        }
       update_stmt (stmt);
       changed = true;
index f28ef31..1830ffa 100644 (file)
@@ -872,6 +872,9 @@ unsigned int execute_free_datastructures (void);
 unsigned int execute_fixup_cfg (void);
 bool fixup_noreturn_call (gimple stmt);
 
+/* In ipa-pure-const.c  */
+void warn_function_noreturn (tree);
+
 #include "tree-flow-inline.h"
 
 void swap_tree_operands (gimple, tree *, tree *);