public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard@codesourcery.com>
To: gcc-patches@gcc.gnu.org
Subject: Fix mode-switching problem for SH SJLJ exceptions
Date: Fri, 20 Jul 2007 14:38:00 -0000	[thread overview]
Message-ID: <87myxruwx4.fsf@firetop.home> (raw)

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))
 		      {

             reply	other threads:[~2007-07-20 11:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-20 14:38 Richard Sandiford [this message]
2007-07-31  9:45 ` Richard Sandiford
2007-07-31 15:06 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87myxruwx4.fsf@firetop.home \
    --to=richard@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).