Patchwork [i386] : Reject invalid constant addresses from ix86_decompose_address

login
register
mail settings
Submitter Uros Bizjak
Date July 24, 2012, 11:31 a.m.
Message ID <CAFULd4aDf+wdTNaeFq4LDDuKeNwGBqHFsTi5Q0exr4dSV-DxfQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/172839/
State New
Headers show

Comments

Uros Bizjak - July 24, 2012, 11:31 a.m.
Hello!

2012-07-24  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53961
	* config/i386/i386.c (ix86_legitimate_address_p): Move check for
	negative constant address for TARET_X32 ...
	(ix86_decompose_address): ... here.  Reject constant addresses
	that don't satisfy x86_64_immediate_operand predicate.

Tested on x86_64-unknown-linux-gnu {,-m32} + various x32 testcases.
Committed to mainline SVN.

Uros.

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 189801)
+++ config/i386/i386.c	(working copy)
@@ -11733,6 +11733,19 @@  ix86_decompose_address (rtx addr, struct ix86_addr
       scale = 1 << scale;
       retval = -1;
     }
+  else if (CONST_INT_P (addr))
+    {
+      if (!x86_64_immediate_operand (addr, VOIDmode))
+	return 0;
+
+      /* Constant addresses are sign extended to 64bit, we have to
+	 prevent addresses from 0x80000000 to 0xffffffff in x32 mode.  */
+      if (TARGET_X32
+	  && val_signbit_known_set_p (SImode, INTVAL (addr)))
+	return 0;
+
+      disp = addr;
+    }
   else
     disp = addr;			/* displacement */
 
@@ -12242,13 +12255,6 @@  ix86_legitimate_address_p (enum machine_mode mode
   rtx base, index, disp;
   HOST_WIDE_INT scale;
 
-  /* Since constant address in x32 is signed extended to 64bit,
-     we have to prevent addresses from 0x80000000 to 0xffffffff.  */
-  if (TARGET_X32
-      && CONST_INT_P (addr)
-      && INTVAL (addr) < 0)
-    return false;
-
   if (ix86_decompose_address (addr, &parts) <= 0)
     /* Decomposition failed.  */
     return false;