+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
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
-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
@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
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
= 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
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));
"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. */
+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
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);
}
int z = 0;
-void g() /* { dg-warning "possible candidate" } */
+void g() /* { dg-warning "might be candidate" } */
{
if (++z > 10)
_exit(0);
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);
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 */
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;
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 *);