This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Possible patch for tree-optimization/13000
Richard Henderson <rth@redhat.com> writes:
> On Thu, Jan 20, 2005 at 09:50:57PM -0500, Ian Lance Taylor wrote:
> > @@ -6764,6 +6765,16 @@ c_finish_bc_stmt (tree *label_p, bool is
> > {
> > tree label = *label_p;
> >
> > + /* In switch statements break is sometimes stylistically used after
> > + a return statement. This can lead to spurious warnings about
> > + control reaching the end of a non-void function when it is
> > + inlined. Note that we are calling block_may_fallthru with
> > + language specific tree nodes; this works because
> > + block_may_fallthru returns true when given something it does not
> > + understand. */
> > + if (! block_may_fallthru (cur_stmt_list))
> > + return NULL_TREE;
> > +
> > if (!label)
> > *label_p = label = create_artificial_label ();
> > else if (TREE_CODE (label) != LABEL_DECL)
>
> Also, you've failed to issue the error needed for
>
> void foo()
> {
> return;
> break;
> }
Hmmm.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.411
diff -p -u -r1.411 c-typeck.c
--- c-typeck.c 19 Jan 2005 09:27:17 -0000 1.411
+++ c-typeck.c 21 Jan 2005 06:41:12 -0000
@@ -43,6 +43,7 @@ Software Foundation, 59 Temple Place - S
#include "target.h"
#include "tree-iterator.h"
#include "tree-gimple.h"
+#include "tree-flow.h"
/* Possible cases of implicit bad conversions. Used to select
diagnostic messages in convert_for_assignment. */
@@ -6762,10 +6763,23 @@ c_finish_loop (location_t start_locus, t
tree
c_finish_bc_stmt (tree *label_p, bool is_break)
{
+ bool skip;
tree label = *label_p;
+ /* In switch statements break is sometimes stylistically used after
+ a return statement. This can lead to spurious warnings about
+ control reaching the end of a non-void function when it is
+ inlined. Note that we are calling block_may_fallthru with
+ language specific tree nodes; this works because
+ block_may_fallthru returns true when given something it does not
+ understand. */
+ skip = !block_may_fallthru (cur_stmt_list);
+
if (!label)
- *label_p = label = create_artificial_label ();
+ {
+ if (!skip)
+ *label_p = label = create_artificial_label ();
+ }
else if (TREE_CODE (label) != LABEL_DECL)
{
if (is_break)
@@ -6775,6 +6789,9 @@ c_finish_bc_stmt (tree *label_p, bool is
return NULL_TREE;
}
+ if (skip)
+ return NULL_TREE;
+
return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
}