public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Commit: Avoid calling convert_to_mode with invalid rtl.
@ 2015-04-14 16:12 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2015-04-14 16:12 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-14 16:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-14 16:12 Commit: Avoid calling convert_to_mode with invalid rtl Nick Clifton

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