public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: Commit: Avoid calling convert_to_mode with invalid rtl.
Date: Tue, 14 Apr 2015 16:12:00 -0000	[thread overview]
Message-ID: <87twwiofj6.fsf@redhat.com> (raw)

Hi Guys,

  Now that the sources are unfrozen I am applying the patch discussed on
  this thread:

    https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00736.html

  It fixes the places where an address offset is computed in the wrong
  mode and needs to be converted to the correct mode.  Since we cannot
  be sure that the offset RTL is valid outside of an address context it
  needs to be forced into a register first.

  Tested with no regressions on an x86_64-pc-linux-gnu and a rl78-elf
  toolchain.

Cheers
  Nick

gcc/ChangeLog
2015-04-14  Nick Clifton  <nickc@redhat.com>

	* expr.c (expand_assignment): Force an address offset computation
	into a register before changing its mode.
	(expand_expr_real_1): Likewise.

Index: expr.c
===================================================================
--- expr.c	(revision 222096)
+++ expr.c	(working copy)
@@ -4879,7 +4879,13 @@
 	  offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
 	  address_mode = get_address_mode (to_rtx);
 	  if (GET_MODE (offset_rtx) != address_mode)
-	    offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
+	    {
+		/* We cannot be sure that the RTL in offset_rtx is valid outside
+		   of a memory address context, so force it into a register
+		   before attempting to convert it to the desired mode.  */
+	      offset_rtx = force_operand (offset_rtx, NULL_RTX);
+	      offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
+	    }
 
 	  /* If we have an expression in OFFSET_RTX and a non-zero
 	     byte offset in BITPOS, adding the byte offset before the
@@ -10258,7 +10264,13 @@
 
 	    address_mode = get_address_mode (op0);
 	    if (GET_MODE (offset_rtx) != address_mode)
-	      offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
+	      {
+		/* We cannot be sure that the RTL in offset_rtx is valid outside
+		   of a memory address context, so force it into a register
+		   before attempting to convert it to the desired mode.  */
+		offset_rtx = force_operand (offset_rtx, NULL_RTX);
+		offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
+	      }
 
 	    /* See the comment in expand_assignment for the rationale.  */
 	    if (mode1 != VOIDmode

                 reply	other threads:[~2015-04-14 16:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87twwiofj6.fsf@redhat.com \
    --to=nickc@redhat.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).