From patchwork Tue Feb 7 21:17:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 725351 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vHxy51n71z9s4s for ; Wed, 8 Feb 2017 08:17:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ewHtZncl"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=YT+ftm+LqDcOlhsBI9XhvMmFjmAHF kDK4tk2aUx9mVnr0xP99GE/8cpovfoZSxEg6nxRfRH37/AMwE8+2Y+PoKYTSEczt IRkQJXW9upcR+fRlxzhbHppyOa2aytY0vfxTSQ+uSg12+vTlZBSIBG3+700tEi5t GK+UIHBRzdIgyQ= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=n3sOxm025ZaOnlUgiuJ4ytXjIS0=; b=ewH tZncl5Xx1BAVdoDc9WZMyAadBPQHzODaSu8jkL97TSf9myjxS8B/q/U8b+RmmZD9 53+TJglw0h5wUhq0vOGvkWsZRSMmNQrUH3WCd2uv71Frj161NTltk2TqY7F4/b9t PryCQVDCyY0+/NuHrkFe49qOCF/NjL1dFxLvPB+8= Received: (qmail 52049 invoked by alias); 7 Feb 2017 21:17:39 -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 52039 invoked by uid 89); 7 Feb 2017 21:17:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=multiplications, arr, ARR 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; Tue, 07 Feb 2017 21:17:28 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D95C0C05AA54 for ; Tue, 7 Feb 2017 21:17:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FDE6685FE; Tue, 7 Feb 2017 21:17:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v17LHOuN007897; Tue, 7 Feb 2017 22:17:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v17LHMP8007896; Tue, 7 Feb 2017 22:17:22 +0100 Date: Tue, 7 Feb 2017 22:17:22 +0100 From: Jakub Jelinek To: Vladimir Makarov Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE on very large functions in ira-costs.c (PR middle-end/79399) Message-ID: <20170207211722.GV1849@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! As mentioned in the PR, on a huge function init_costs attempts to allocate 124 * 17380077 bytes, 124 is max_struct_costs_size and 17380077 is cost_elements_num. The problem is that the multiplication is done in int type, so it overflows and we attempt to allocate 0xffffffff8074aacc bytes. Other similar multiplications in ira-costs.c use size_t as type of at least one operand, so it works properly. The following patch fixes it by making sure struct_costs_size and max_struct_costs_size have size_t type. The first hunk shouldn't result in more memory being used, on 32-bit host it is not any change and the field is followed by a pointer, so on 64-bit hosts there has been padding that we now use. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-02-07 Jakub Jelinek Richard Biener PR middle-end/79399 * ira-int.h (struct target_ira_int): Change x_max_struct_costs_size type from int to size_t. * ira-costs.c (struct_costs_size): Change type from int to size_t. Jakub --- gcc/ira-int.h.jj 2017-01-01 12:45:39.000000000 +0100 +++ gcc/ira-int.h 2017-02-07 09:29:32.694102809 +0100 @@ -782,7 +782,7 @@ struct target_ira_int { /* Initialized once. It is a maximal possible size of the allocated struct costs. */ - int x_max_struct_costs_size; + size_t x_max_struct_costs_size; /* Allocated and initialized once, and used to initialize cost values for each insn. */ --- gcc/ira-costs.c.jj 2017-01-16 12:28:35.000000000 +0100 +++ gcc/ira-costs.c 2017-02-07 11:44:26.534868418 +0100 @@ -74,7 +74,7 @@ static struct costs *costs; static struct costs *total_allocno_costs; /* It is the current size of struct costs. */ -static int struct_costs_size; +static size_t struct_costs_size; /* Return pointer to structure containing costs of allocno or pseudo with given NUM in array ARR. */