[PATCH] PR middle-end/19774

Josh Conner jconner@apple.com
Wed Mar 14 19:21:00 GMT 2007


SJLJ exception handling is incompatible with alloca (and hence,
variable-length arrays).  A function which calls alloca and then catches
an exception may discover upon catching that the alloca'd memory has
been corrupted.

This is occurring because SJLJ exception handling stores function
context (SP, FP, etc.) at the start of a function, so any calls to
alloca aren't taken into consideration.

The attached patch causes the function context to be updated following
every call to alloca.  It implements this by creating a NOTE_INSN during
expansion of builtin_alloca's, which the EH logic processes to induce a
re-calculation of stack context.

Regression tested with no new failures on...

Target: sh-none-elf
Configured with:
/home/josh/work/testing/builds/gcc-mainline-sh/gcc/configure
--prefix=/home/josh/work/testing/builds/gcc-mainline-sh/installed
--target=sh-none-elf --disable-nls --enable-languages=c,c++
--with-newlib --enable-sjlj-exceptions

OK for mainline?

:ADDPATCH middle-end:

- Josh

2007-03-14  Josh Conner  <jconner@apple.com>

        PR middle-end/19774
        * builtins.c (expand_builtin_alloca): Create NOTE_INSN_ALLOCA.
        * except.c (sjlj_emit_function_enter): Split into...
        (sjlj_generate_setjmp_sequence): ..., with logic to handle
        unregistering.
        (sjlj_emit_context_saves): ..., with logic for handling
        NOTE_INSN_ALLOCA.
        (sjlj_build_landing_pads): Call sjlj_emit_context_saves
        instead of sjlj_emit_function_enter.
        * final.c (final_scan_insn): Handle NOTE_INSN_ALLOCA.
        * insn-notes.def: Add NOTE_INSN_ALLOCA.

2007-03-14  Josh Conner  <jconner@apple.com>

	PR middle-end/19774
	* g++.dg/eh/alloca.C: New.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr30196.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070314/78c3b8c4/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: alloca.C
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070314/78c3b8c4/attachment-0001.ksh>


More information about the Gcc-patches mailing list