public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: gcc-patches@gcc.gnu.org
Cc: Uros Bizjak <ubizjak@gmail.com>
Subject: PATCH: PR target/52146: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF
Date: Fri, 10 Feb 2012 17:42:00 -0000	[thread overview]
Message-ID: <20120210172506.GA19409@intel.com> (raw)

Hi,

Since constant address in x32 is signed extended to 64bit, negative
displacement without base nor index is out of range.  OK for trunk?

Thanks.


H.J.
---
gcc/

2012-02-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/52146
	* config/i386/i386.c (ix86_legitimate_address_p): Disallow
	negative constant address for x32.

gcc/testsuite/

2012-02-10  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/52146
	* gcc.target/i386/pr52146.c: New.

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 009dd53..0bb94a7 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -12107,6 +12107,15 @@ ix86_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
 		   || !ix86_legitimate_constant_p (Pmode, disp)))
 	/* Displacement is not constant.  */
 	return false;
+      else if (TARGET_X32
+	       && !base
+	       && !index
+	       && CONST_INT_P (disp)
+	       && INTVAL (disp) < 0)
+	/* Since constant address in x32 is signed extended to 64bit,
+	   negative displacement without base nor index is out of
+	   range.  */
+	return false;
       else if (TARGET_64BIT
 	       && !x86_64_immediate_operand (disp, VOIDmode))
 	/* Displacement is out of range.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr52146.c b/gcc/testsuite/gcc.target/i386/pr52146.c
new file mode 100644
index 0000000..68bdeff
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr52146.c
@@ -0,0 +1,17 @@
+/* { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && { ! { ia32 } } } } } */
+/* { dg-options "-O2 -mx32" } */
+
+void test1() {
+  int* apic_tpr_addr = (int *)0xfee00080;
+  *apic_tpr_addr += 4;
+}
+void test2() {
+  volatile int* apic_tpr_addr = (int *)0xfee00080;
+  *apic_tpr_addr = 0;
+}
+void test3() {
+  volatile int* apic_tpr_addr = (int *)0x7fffffff;
+  *apic_tpr_addr = 0;
+}
+
+/* { dg-final { scan-assembler-not "-18874240" } } */

             reply	other threads:[~2012-02-10 17:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10 17:42 H.J. Lu [this message]
2012-02-10 17:44 ` H.J. Lu
2012-02-10 18:01   ` Uros Bizjak
2012-02-10 18:25     ` H.J. Lu

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=20120210172506.GA19409@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=ubizjak@gmail.com \
    /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).