From patchwork Wed May 1 20:26:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 240811 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 0180A2C00C8 for ; Thu, 2 May 2013 06:26:26 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Zi7FzoTCxpw8eR36p8QdH4lA2E+Wqi11+NMOyOR3CBXlNi dCW72S9BLpv4NRdcBm+9MBTDyUSBNAYGz8OX5A2kTw5f/mpKRUB0d6P70PkKXLjU NhmAKKetDEUe1bGEPpQebz5GCvlGYTuZ8r+/FXkQ2oHytZQZG58jjTaY91c4k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=EDmBwJycHP01Y+lZYtVrkxSGiBo=; b=BKhO9fwEZheBcwX4KkN0 Ti23n8CPG+0dZq6Pxz3FDaGU3gFUKLL94eBo8bh+DakL25+s5mrbffoQ4j4V2UWP mQD/XZ8+x/ofG0EIdboxpcM9nCSMu9rh+PgQhYFkhPCDx3MU0MrlGL1O1j7/DvHL OjypZ56XWKAop1fmGWGNfmo= Received: (qmail 7393 invoked by alias); 1 May 2013 20:26:20 -0000 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 Received: (qmail 7381 invoked by uid 89); 1 May 2013 20:26:20 -0000 X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 01 May 2013 20:26:19 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r41KQH2T026082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 1 May 2013 16:26:17 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-32.phx2.redhat.com [10.3.113.32]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r41KQHba012269 for ; Wed, 1 May 2013 16:26:17 -0400 Message-ID: <51817A69.90805@redhat.com> Date: Wed, 01 May 2013 14:26:17 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5 MIME-Version: 1.0 To: gcc-patches Subject: [RFA][PATCH] Fix tree-optimization/57124 X-Virus-Found: No range_fits_type_p erroneously returns true in cases where the range has overflowed. So for example, we might have a range [0, +INF(OVF)] and conclude the range fits in an unsigned type. This in turn can cause VRP to rewrite a conditional in an unsafe way as seen by the testcase. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. OK for the trunk? commit 45d8f974a4fae7bf07b7213b4ccda81fe410d49b Author: Jeff Law Date: Wed May 1 12:33:20 2013 -0600 PR tree-optimization/57124 * tree-vrp.c (range_fits_type_p): If min/max of the range has overflowed, then the range does not fit the type. PR tree-optimization/57124 * gcc.c-torture/execute/pr57124.c: New test. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 50a3b1d..658ddda 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-04-26 Jeff Law + + PR tree-optimization/57124 + * tree-vrp.c (range_fits_type_p): If min/max of the range has + overflowed, then the range does not fit the type. + 2013-04-30 Greta Yorsh * config/arm/thumb2.md (thumb2_incscc, thumb2_decscc): Delete. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1016036..3ed531e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-05-01 Jeff Law + + PR tree-optimization/57124 + * gcc.c-torture/execute/pr57124.c: New test. + 2013-04-30 Thomas Koenig PR fortran/57071 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57124.c b/gcc/testsuite/gcc.c-torture/execute/pr57124.c new file mode 100644 index 0000000..835d249 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr57124.c @@ -0,0 +1,27 @@ +__attribute__ ((noinline)) +foo(short unsigned int *p1, short unsigned int *p2) +{ + short unsigned int x1, x4; + int x2, x3, x5, x6; + unsigned int x7; + + x1 = *p1; + x2 = (int) x1; + x3 = x2 * 65536; + x4 = *p2; + x5 = (int) x4; + x6 = x3 + x4; + x7 = (unsigned int) x6; + if (x7 <= 268435455U) + abort (); + exit (0); +} + +main() +{ + short unsigned int x, y; + x = -5; + y = -10; + foo (&x, &y); +} + diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 6ed353f..02f2f19 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -8537,7 +8537,9 @@ range_fits_type_p (value_range_t *vr, unsigned precision, bool unsigned_p) /* Now we can only handle ranges with constant bounds. */ if (vr->type != VR_RANGE || TREE_CODE (vr->min) != INTEGER_CST - || TREE_CODE (vr->max) != INTEGER_CST) + || TREE_CODE (vr->max) != INTEGER_CST + || is_negative_overflow_infinity (vr->min) + || is_positive_overflow_infinity (vr->max)) return false; /* For sign changes, the MSB of the double_int has to be clear.