From patchwork Fri Feb 10 17:25:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 140696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id CAAA4B6EF1 for ; Sat, 11 Feb 2012 04:25:26 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329499527; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=fDmQz4uTo/f0oDAgLlXv 4uOUWhs=; b=Tj1zkuFh7zCXGpO8a8Skc97N4dQKlBeWcoMlBXpsGNvKsb+G0Igu NVmA+SY4gP8W2KpElmN2nn3MY9/14U6tzF7acGMOlABD+xgRq72pykEveutniW3f iNdhHcSM5OY8IwtxjV/20lGvbDdY+T0ZyhTKfFXc3EEtfXZypwRRCfQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=I2lL+H0EPysqikkv6B9IPbaeBw7CP3Uo8CvUFA6WVgM5FSndRbLqznYsqne1Jn 5a0Jij+sEvMIpa+KCup+4RWadiLrAzTIMfaQU5mM27aCM9lNT5H73uNxJYTgTp9A V8bNUxyW93MVRI/LBSYj9/z4M5ZziS6DGiWATvticI2Jk=; Received: (qmail 19238 invoked by alias); 10 Feb 2012 17:25:21 -0000 Received: (qmail 19216 invoked by uid 22791); 10 Feb 2012 17:25:20 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga03.intel.com (HELO mga03.intel.com) (143.182.124.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Feb 2012 17:25:07 +0000 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 10 Feb 2012 09:25:07 -0800 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by azsmga001.ch.intel.com with ESMTP; 10 Feb 2012 09:25:06 -0800 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 977E4C183C; Fri, 10 Feb 2012 09:25:06 -0800 (PST) Date: Fri, 10 Feb 2012 09:25:06 -0800 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak Subject: PATCH: PR target/52146: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF Message-ID: <20120210172506.GA19409@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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 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" } } */