From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8083 invoked by alias); 7 Oct 2016 12:18:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 7195 invoked by uid 89); 7 Oct 2016 12:18:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1113, sk:bschmid, U*bschmidt, bschmidt@redhat.com X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Oct 2016 12:18:28 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA5424E356 for ; Fri, 7 Oct 2016 12:18:27 +0000 (UTC) Received: from localhost.localdomain (vpn1-7-173.ams2.redhat.com [10.36.7.173]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u97CIQ52011784 for ; Fri, 7 Oct 2016 08:18:27 -0400 To: GCC Patches From: Bernd Schmidt Subject: Fix PR77880 Message-ID: Date: Fri, 07 Oct 2016 12:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8DE3B0B112CAF1917B039CE2" X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00477.txt.bz2 This is a multi-part message in MIME format. --------------8DE3B0B112CAF1917B039CE2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 238 When encountering a memcmp with something like ULONG_MAX for the size, a calculation can overflow in by_pieces_ninsns because it uses int rather than HOST_WIDE_INT. Bootstrapped & tested on x86_64-linux, committed as obvious. Bernd --------------8DE3B0B112CAF1917B039CE2 Content-Type: text/x-patch; name="bypieces.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bypieces.diff" Content-length: 925 Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 240861) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2016-10-07 Bernd Schmidt + + PR tree-optimization/77880 + * expr.c (by_pieces_ninsns): Use unsigned HOST_WIDE_INT where + necessary. + 2016-10-07 Marek Polacek PR c++/77803 Index: gcc/expr.c =================================================================== --- gcc/expr.c (revision 240861) +++ gcc/expr.c (working copy) @@ -785,7 +785,7 @@ by_pieces_ninsns (unsigned HOST_WIDE_INT case COMPARE_BY_PIECES: int batch = targetm.compare_by_pieces_branch_ratio (mode); int batch_ops = 4 * batch - 1; - int full = n_pieces / batch; + unsigned HOST_WIDE_INT full = n_pieces / batch; n_insns += full * batch_ops; if (n_pieces % batch != 0) n_insns++; --------------8DE3B0B112CAF1917B039CE2--