This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] rearrange main() stack/eh stuff
- From: DJ Delorie <dj at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dj at redhat dot com
- Date: Fri, 21 Dec 2001 21:45:18 -0500
- Subject: [patch] rearrange main() stack/eh stuff
Tested on linux with and without --enable-sjlj-exceptions (c c++ f
objc), no regressions. Fixes a bug whereby the sjlj EH state
(including %esp) is registered before the stack is aligned, breaking
g++.old-deja/unwind1.C on cygwin (which doesn't align the stack until
main() does it).
2001-12-21 DJ Delorie <dj@redhat.com>
* function.c (expand_main_function): Make sure stack adjustments
happen before sjlj exception setup.
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.336
diff -p -3 -r1.336 function.c
*** function.c 2001/12/09 20:13:04 1.336
--- function.c 2001/12/22 02:35:34
*************** expand_main_function ()
*** 6279,6286 ****
if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
{
int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
! rtx tmp;
/* Forcibly align the stack. */
#ifdef STACK_GROWS_DOWNWARD
tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
--- 6279,6287 ----
if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
{
int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
! rtx tmp, seq;
+ start_sequence ();
/* Forcibly align the stack. */
#ifdef STACK_GROWS_DOWNWARD
tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
*************** expand_main_function ()
*** 6297,6302 ****
--- 6298,6313 ----
/* Enlist allocate_dynamic_stack_space to pick up the pieces. */
tmp = force_reg (Pmode, const0_rtx);
allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
+ seq = gen_sequence ();
+ end_sequence ();
+
+ for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
+ if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
+ break;
+ if (tmp)
+ emit_insn_before (seq, tmp);
+ else
+ emit_insn (seq);
}
#endif