This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix mode-switching problem for SH SJLJ exceptions


Functions that return a value usually end with the sequence:

    A: (clobber (reg H))
    ...
    B: (set (reg H) (reg P))
    ...
    C: (use (reg H))

where H is the hard return register and P is the pseudo register
to which return values are assigned.

mode-switching.c uses a specially-split exit block to enforce MODE_EXIT
(the mode required on exit from a function).  The code that creates this
block -- create_pre_exit -- tries to find insn B and starts the new block
immediately before (or sometimes immediately after) it.

However, B can be deleted if P is never initialised.  In this case,
create_pre_exit splits the block immediately before A instead.
The code only searches for A and B in the fallthrough predecessor
to the exit block; it assumes that P is never initialised if the
block contains neither A nor B.

In some cases B may be made up of several individual insns.
create_pre_exit therefore records the range of modified registers
and stops on the first SET that doesn't assign to part of H.
It then asserts that it has found a SET or CLOBBER for the
whole of H (except in some corner cases).

This shows up a problem on SJLJ targets, where the call to the SJLJ
unregister function is inserted between A and B.  If B has been deleted,
the first SET we find may be setting up the argument to that call.
We then stop the search without having found either A or B, so the
assertion triggers.

At this point we have already searched past the call itself, and this
seems bogus.  We are supposed to enforce MODE_EXIT _after_ the last call.
I therefore just treated searches that reach a call in the same way as
searches that reach the beginning of a block.

Bootstrapped & regression-tested on x86_64-linux-gnu.  Also regression-tested
on sh-elf (multilibs {,-m2,-m3,-m4,-m4/-ml}) and sh-wrs-vxworks.  OK to
install?

Richard


gcc/
	* mode-switching.c (create_pre_exit): Don't search past calls.

Index: gcc/mode-switching.c
===================================================================
--- gcc/mode-switching.c	(revision 126715)
+++ gcc/mode-switching.c	(working copy)
@@ -246,6 +246,17 @@ create_pre_exit (int n_entities, int *en
 
 		if (INSN_P (return_copy))
 		  {
+		    /* When using SJLJ exceptions, the call to the
+		       unregister function is inserted between the
+		       clobber of the return value and the copy.
+		       We do not want to split the block before this
+		       or any other call; if we have not found the
+		       copy yet, the copy must have been deleted.  */
+		    if (CALL_P (return_copy))
+		      {
+			short_block = 1;
+			break;
+		      }
 		    return_copy_pat = PATTERN (return_copy);
 		    switch (GET_CODE (return_copy_pat))
 		      {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]