From 43e05e45bcd3092ef7fb02e537ca7645607dbede Mon Sep 17 00:00:00 2001 From: Steven Bosscher Date: Sat, 1 Jan 2005 16:15:23 +0000 Subject: re PR middle-end/17544 (incorrect -Wunreachable-code warning for mains with a return statement) * emit-rtl.c (add_insn_before): Fix comment typo. 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. cp/ PR middle-end/17544 * decl.c (finish_function): Fix comment. Annotate the compiler generated return with the current file name and line 0. testsuite/ * gcc.dg/20041231-1.C: New test. * g++.dg/warn/Wunreachable-code-1.C: New test. From-SVN: r92784 --- gcc/tree-cfg.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'gcc/tree-cfg.c') diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index e020676..a68c964 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -1,5 +1,5 @@ /* 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 This file is part of GCC. @@ -1323,8 +1323,11 @@ remove_useless_stmts_warn_notreached (tree stmt) 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)) @@ -2021,11 +2024,17 @@ remove_bb (basic_block bb) 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 -- cgit v1.1