summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/common.opt4
-rw-r--r--gcc/doc/invoke.texi29
-rw-r--r--gcc/ipa-pure-const.c16
-rw-r--r--gcc/opts.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/noreturn-4.c2
-rw-r--r--gcc/testsuite/gcc.dg/noreturn-7.c6
-rw-r--r--gcc/tree-cfg.c18
-rw-r--r--gcc/tree-cfgcleanup.c18
-rw-r--r--gcc/tree-flow.h3
11 files changed, 82 insertions, 38 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 742950c041b..59f69396a6e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/common.opt b/gcc/common.opt
index a96158237dd..f001e026fc9 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -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
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 777c3842ab5..3519ead1c59 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index 766c8fc6456..da8d442107b 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -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));
diff --git a/gcc/opts.c b/gcc/opts.c
index 8699ec33703..e304ce5c94b 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -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. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e7eae084491..372d59518ea 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.dg/noreturn-4.c b/gcc/testsuite/gcc.dg/noreturn-4.c
index bcc29dac69a..6fe144754d0 100644
--- a/gcc/testsuite/gcc.dg/noreturn-4.c
+++ b/gcc/testsuite/gcc.dg/noreturn-4.c
@@ -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);
}
diff --git a/gcc/testsuite/gcc.dg/noreturn-7.c b/gcc/testsuite/gcc.dg/noreturn-7.c
index 1913be1fe1d..fd2be2d56c0 100644
--- a/gcc/testsuite/gcc.dg/noreturn-7.c
+++ b/gcc/testsuite/gcc.dg/noreturn-7.c
@@ -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);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index f46556fe59a..406479416ae 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -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 */
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index fc2141f48c1..8dec8c76431 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -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;
diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h
index f28ef31c2a9..1830ffa874e 100644
--- a/gcc/tree-flow.h
+++ b/gcc/tree-flow.h
@@ -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 *);