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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D8BEA385840F for ; Thu, 2 Dec 2021 14:29:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8BEA385840F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-139-Y_h3ObiOMJuMw4ixgZ4gEw-1; Thu, 02 Dec 2021 09:29:42 -0500 X-MC-Unique: Y_h3ObiOMJuMw4ixgZ4gEw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 888C6874981 for ; Thu, 2 Dec 2021 14:29:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 151935F4E7; Thu, 2 Dec 2021 14:29:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1B2ETbur1019993 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 2 Dec 2021 15:29:38 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1B2ETbBc1019992; Thu, 2 Dec 2021 15:29:37 +0100 Date: Thu, 2 Dec 2021 15:29:37 +0100 From: Jakub Jelinek To: Vladimir Makarov Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [PR103437] [committed] IRA: Process multiplication overflow in priority calculation for allocno assignments Message-ID: <20211202142937.GI2646553@tucnak> Reply-To: Jakub Jelinek References: <116e765c-ea89-47f4-600f-af115dd561c3@redhat.com> <20211202140021.GH2646553@tucnak> <3bb6317f-b049-13f1-1bac-6ffd753e9685@redhat.com> MIME-Version: 1.0 In-Reply-To: <3bb6317f-b049-13f1-1bac-6ffd753e9685@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 02 Dec 2021 14:29:45 -0000 On Thu, Dec 02, 2021 at 09:23:20AM -0500, Vladimir Makarov wrote: > > On 2021-12-02 09:00, Jakub Jelinek wrote: > > On Thu, Dec 02, 2021 at 08:53:31AM -0500, Vladimir Makarov via Gcc-patches wrote: > > > The following patch fixes > > > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103437 > > > > > > The patch was successfully bootstrapped and tested on x86-64. There is no > > > test as the bug occurs on GCC built with sanitizing for an existing go test. > > I'm afraid we can't use __builtin_smul_overflow, not all system compilers > > will have that. > > But, as it is done in int and we kind of rely on int being 32-bit on host > > and rely on long long being 64-bit, I think you can do something like: > > long long priorityll = (long long) mult * diff; > > priority = priorityll; > > if (priorityll != priority > > ... > > > > > My 1st version of the patch was based on long long but the standard does not > guarantee that int size is smaller than long long size.  Although it is true > for all targets supported by GCC. > > Another solution would be to switching to int32_t instead of int for costs > but it will require a lot of changes in RA code. > > I see your point for usage system compiler different from GCC and LLVM.  I > guess I could change it to > > #if __GNUC__ >= 5 #ifdef __has_builtin # if __has_builtin(__builtin_smul_overflow) would be the best check. And you can just gcc_assert (sizeof (long long) >= 2 * sizeof (int)); in the fallback code ;) Jakub