+2005-01-01 Steven Bosscher <stevenb@suse.de>
+
+ PR middle-end/17544
+ * c-decl.c (finish_function): If compiling C99, annotate the
+ compiler generated return with the current file name and line 0.
+ * tree-cfg.c (remove_useless_stmts_warn_notreached): Only warn if
+ the source line is greater than 0.
+ (remove_bb): Likewise.
+
2004-12-31 Richard Henderson <rth@redhat.com>
PR tree-opt/19042
/* Process declarations and variables for C compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
#include "config.h"
#include "system.h"
#include "coretypes.h"
+#include "input.h"
#include "tm.h"
#include "intl.h"
#include "tree.h"
else
{
if (flag_isoc99)
- c_finish_return (integer_zero_node);
+ {
+ tree stmt = c_finish_return (integer_zero_node);
+ /* Hack. We don't want the middle-end to warn that this
+ return is unreachable, so put the statement on the
+ special line 0. */
+ annotate_with_file_line (stmt, input_filename, 0);
+ }
}
}
+2005-01-01 Steven Bosscher <stevenb@suse.de>
+
+ PR middle-end/17544
+ * decl.c (finish_function): Fix comment. Annotate the compiler
+ generated return with the current file name and line 0.
+
2004-12-31 Richard Henderson <rth@redhat.com>
PR middle-end/17799
/* Process declarations and variables for C++ compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004,2005 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
{
if (DECL_MAIN_P (current_function_decl))
{
- /* Make it so that `main' always returns 0 by default. */
+ tree stmt;
+
+ /* Make it so that `main' always returns 0 by default (or
+ 1 for VMS). */
#if VMS_TARGET
- finish_return_stmt (integer_one_node);
+ stmt = finish_return_stmt (integer_one_node);
#else
- finish_return_stmt (integer_zero_node);
+ stmt = finish_return_stmt (integer_zero_node);
#endif
+ /* Hack. We don't want the middle-end to warn that this
+ return is unreachable, so put the statement on the
+ special line 0. */
+ annotate_with_file_line (stmt, input_filename, 0);
}
/* Finish dealing with exception specifiers. */
/* Emit RTL for the GCC expander.
Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
if (INSN_P (insn))
bb->flags |= BB_DIRTY;
/* Should not happen as first in the BB is always either NOTE or
- LABEl. */
+ LABEL. */
gcc_assert (BB_HEAD (bb) != insn
/* Avoid clobbering of structure when creating new BB. */
|| BARRIER_P (insn)
+2005-01-01 Steven Bosscher <stevenb@suse.de>
+
+ * gcc.dg/20041231-1.C: New test.
+ * g++.dg/warn/Wunreachable-code-1.C: New test.
+
2004-12-30 David Edelsohn <edelsohn@gnu.org>
* gfortran.fortran-torture/execute/read_eof.f90: Open scratch
--- /dev/null
+/* PR17544 Incorrect -Wunreachable-code warning
+ Origin: sebor@roguewave.com
+
+ G++ appends a "return 0;" when finishing a function, but it was not
+ given a source location. The gimplifier thinks a return statement
+ needs a locus so it would add one, making the compiler generated code
+ visible to the unreachable code warning. */
+
+/* { dg-do compile } */
+/* { dg-options "-O -Wunreachable-code" } */
+
+int
+main (int argc, char *argv[])
+{
+ const char* const s = argc < 2 ? "" : argv [1];
+ int i = 0;
+ do {
+ ++i;
+ } while (i < s [0]);
+ return i;
+}
+
--- /dev/null
+/* PR17544 Incorrect -Wunreachable-code warning
+ Origin: Giovanni Bajo
+
+ In C99 we append a "return 0;" when finishing a function, but it was
+ not given a source location. The gimplifier thinks a return statement
+ needs a locus so it would add one, making the compiler generated code
+ visible to the unreachable code warning. */
+
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -O -Wunreachable-code" } */
+
+int main (void) // 1
+{ // 2
+ return 0; // 3
+} // 4
/* Control flow functions for trees.
- Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>
This file is part of GCC.
if (EXPR_HAS_LOCATION (stmt))
{
location_t loc = EXPR_LOCATION (stmt);
- warning ("%Hwill never be executed", &loc);
- return true;
+ if (LOCATION_LINE (loc) > 0)
+ {
+ warning ("%Hwill never be executed", &loc);
+ return true;
+ }
}
switch (TREE_CODE (stmt))
since this way we lose warnings for gotos in the original
program that are indeed unreachable. */
if (TREE_CODE (stmt) != GOTO_EXPR && EXPR_HAS_LOCATION (stmt) && !loc)
+ {
+ source_locus t;
+
#ifdef USE_MAPPED_LOCATION
- loc = EXPR_LOCATION (stmt);
+ t = EXPR_LOCATION (stmt);
#else
- loc = EXPR_LOCUS (stmt);
+ t = EXPR_LOCUS (stmt);
#endif
+ if (t && LOCATION_LINE (*t) > 0)
+ loc = t;
+ }
}
/* If requested, give a warning that the first statement in the