From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id DECAA3894420 for ; Thu, 8 Oct 2020 09:37:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DECAA3894420 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-nZWeIsiCMfaCy9AueibZ6g-1; Thu, 08 Oct 2020 05:37:00 -0400 X-MC-Unique: nZWeIsiCMfaCy9AueibZ6g-1 Received: by mail-wm1-f71.google.com with SMTP id g125so2950683wme.1 for ; Thu, 08 Oct 2020 02:37:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=25Ob+NV8tfhhTaG1hxlGJKlufsYRyC1ALxA4AZp3g5M=; b=IJ0I/CFQ/bnp91kzXEwsZoV7cEhT4jpByJcIENFe0Jo+fNK2tcPA6gLU0b8wmadR8n DYbaFCItXCjXO+bS/q2VW+7rBvpuSI15r4Ll45OmXJ0nBYJjPdlsMY80Tnlhajo3NqrW 8kllMmM/5iDM7h9XbGbnaOeCrSAlodGeBKfyDfenYLmg4kGvWKnrAMJk6Aa95vk1WlSY Z4a6J1Zqlie+M3FQJ/p1D6zVlNiG2i7aiCbIEIHWwUw6HTHxBeu6iQ3UKP4onZr3PyaG JJiNcWzNW55iKmq/Q7xvXMnJFGv9zQ4GzSPKIk19l3DZ3yKJ6wONUt+SpsxUZ+90d3Jg 5+Sw== X-Gm-Message-State: AOAM533JfW8V1jr8wB++r+wfPiTZYqeif0ew4p1EjR+OzFYUuxllyMK5 0BuHpvI+YgFpxmRayCAjwET5eaG0Bx0msRrxOiOi+1t861XqmwVuMACS3PiqLFNsxNG4hw0qmKC NhICtqEfzAh5Z2FCthA== X-Received: by 2002:adf:f10e:: with SMTP id r14mr7860927wro.337.1602149819082; Thu, 08 Oct 2020 02:36:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/nNNm402aiL0/NS14CI3WebyXfkT5rQZBt16SPNrrnF2xYu4cKp7soU8JZD5VlAFCKCzIXw== X-Received: by 2002:adf:f10e:: with SMTP id r14mr7860903wro.337.1602149818838; Thu, 08 Oct 2020 02:36:58 -0700 (PDT) Received: from abulafia.quesejoda.com ([95.169.226.213]) by smtp.gmail.com with ESMTPSA id t4sm1533933wra.75.2020.10.08.02.36.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Oct 2020 02:36:58 -0700 (PDT) To: gcc-patches From: Aldy Hernandez Subject: [PUSHED] Fix PR97315 (part 2 of 2) Message-ID: <79b7d4c5-a6fd-8661-7e03-7c5f2156f27c@redhat.com> Date: Thu, 8 Oct 2020 11:36:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Oct 2020 09:37:04 -0000 This fixes the second testcase in the PR. I've tested Andrew's patch and pushed it. Aldy gcc/ChangeLog: PR tree-optimization/97315 * range-op.cc (value_range_with_overflow): Change any non-overflow calculation in which both bounds are overflow/underflow to be undefined. gcc/testsuite/ChangeLog: * gcc.dg/pr97315-2.c: New test. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 87c6d82f2ac..22bc23c1bbf 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -287,6 +287,15 @@ value_range_with_overflow (irange &r, tree type, } else { + // If both bounds either underflowed or overflowed, then the result + // is undefined. + if ((min_ovf == wi::OVF_OVERFLOW && max_ovf == wi::OVF_OVERFLOW) + || (min_ovf == wi::OVF_UNDERFLOW && max_ovf == wi::OVF_UNDERFLOW)) + { + r.set_undefined (); + return; + } + // If overflow does not wrap, saturate to [MIN, MAX]. wide_int new_lb, new_ub; if (min_ovf == wi::OVF_UNDERFLOW) diff --git a/gcc/testsuite/gcc.dg/pr97315-2.c b/gcc/testsuite/gcc.dg/pr97315-2.c new file mode 100644 index 00000000000..5dd1b6a3fc7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97315-2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void c(int); + +int a; +void b() +{ + if (a >= 2147483647) + c(a + 1); +}