This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch to fix unreached-return regressions
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 03 Apr 2005 12:38:46 -0700
- Subject: patch to fix unreached-return regressions
This fixes another --enable-mapped-location regression.
As explained in the comment, marking the fake return
with UNKNOWN_LOCATION doesn't prevent later code from
setting it to a real line, and then we get a bad warning.
Using BUILTINS_LOCATION works.
It's a bit of a kludge though. Some kind of EXPR_ARTIFICIAL
bit might be cleaner, if such a bit is available.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2005-04-03 Per Bothner <per@bothner.com>
* c-decl.c (finish_function): If USE_MAPPED_LOCATION set the location
of the artification 'return 0' in main() to BUILTINS_LOCATION.
* tree-cfg.c (remove_bb): Check that location isn't BUILTINS_LOCATION
before warning.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.644
diff -u -p -r1.644 c-decl.c
--- c-decl.c 1 Apr 2005 16:16:19 -0000 1.644
+++ c-decl.c 3 Apr 2005 19:14:21 -0000
@@ -6272,12 +6272,18 @@ finish_function (void)
if (flag_isoc99)
{
tree stmt = c_finish_return (integer_zero_node);
+#ifdef USE_MAPPED_LOCATION
+ /* Hack. We don't want the middle-end to warn that this return
+ is unreachable, so we mark its location as special. Using
+ UNKNOWN_LOCATION has the problem that it gets clobbered in
+ annotate_one_with_locus. A cleaner solution might be to
+ ensure ! should_carry_locus_p (stmt), but that needs a flag.
+ */
+ SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
+#else
/* Hack. We don't want the middle-end to warn that this
return is unreachable, so put the statement on the
special line 0. */
-#ifdef USE_MAPPED_LOCATION
- SET_EXPR_LOCATION (stmt, UNKNOWN_LOCATION);
-#else
annotate_with_file_line (stmt, input_filename, 0);
#endif
}
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.164
diff -u -p -r2.164 tree-cfg.c
--- tree-cfg.c 18 Mar 2005 10:09:51 -0000 2.164
+++ tree-cfg.c 3 Apr 2005 19:14:24 -0000
@@ -2129,7 +2129,7 @@ remove_bb (basic_block bb)
loop above, so the last statement we process is the first statement
in the block. */
#ifdef USE_MAPPED_LOCATION
- if (warn_notreached && loc != UNKNOWN_LOCATION)
+ if (warn_notreached && loc > BUILTINS_LOCATION)
warning ("%Hwill never be executed", &loc);
#else
if (warn_notreached && loc)