This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] fix DECL_INITIAL output for local statics
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: zadeck at naturalbridge dot com
- Date: Mon, 24 Dec 2007 11:34:10 -0800
- Subject: [lto] fix DECL_INITIAL output for local statics
An interesting corner case was introduced with the recent rewrite of how
we output local statics. Say we have a static var X in static function
FOO and FOO is inlined into BAR. This happens to be the only use of
FOO, so cgraph determines that FOO is now redundant and decides that it
doesn't need to be output.
Now the LTO writing phase would write X while writing BAR...but it
wouldn't write X's DECL_INITIAL because DECL_CONTEXT (X) != BAR. On the
LTO reading side, then, X would no longer have a DECL_INITIAL, which
would make users of X most unhappy.
The fix is to always output the DECL_INITIAL the first time the variable
gets written out, no exceptions. We also won't necessarily restore
DECL_CONTEXT properly...but I think that was a problem with the original
code anyway.
Committed to the LTO branch.
-Nathan
2007-12-24 Nathan Froyd <froydnj@codesourcery.com>
* lto-function-out.c (output_local_vars): Output DECL_INITIAL
regardless of whether we are outputting the function in which
it was defined.
Index: lto-function-out.c
===================================================================
--- lto-function-out.c (revision 131137)
+++ lto-function-out.c (working copy)
@@ -1857,16 +1857,15 @@ output_local_vars (struct output_block *
if (DECL_CONTEXT (lv) == fn->decl)
{
output_uleb128 (ob, 1); /* Restore context. */
- if (DECL_INITIAL (lv))
- output_expr_operand (ob, DECL_INITIAL (lv));
- else
- output_zero (ob); /* DECL_INITIAL. */
}
- else
+ else
{
- output_zero (ob); /* Restore context. */
- output_zero (ob); /* DECL_INITIAL. */
+ output_zero (ob); /* Restore context. */
}
+ if (DECL_INITIAL (lv))
+ output_expr_operand (ob, DECL_INITIAL (lv));
+ else
+ output_zero (ob); /* DECL_INITIAL. */
}
}
else