From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dog.elm.relay.mailchannels.net (dog.elm.relay.mailchannels.net [23.83.212.48]) by sourceware.org (Postfix) with ESMTPS id 30B3D3858D26 for ; Fri, 26 Jul 2024 17:39:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30B3D3858D26 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30B3D3858D26 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.212.48 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722015550; cv=pass; b=sqAUkNpb/69kowYPWV/o+oYA52//fVb5orp84u9q7ADjZCY2bDm5FEx2XXxrbJ7Qkg3JxWD3jG8L5OPBL8IRctXwQSz70JypMYda2VESgkQx8rRv5FiNl7ti5Dd2dWZ8fgQj0OZwtJCxyHm2mL5aWIWauZoRRLIlRpLtD45rbY4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722015550; c=relaxed/simple; bh=6BscG+ZZl7gcn3sFBEal0GHLjo/pn2LhV1TMq2098kM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=hcBsR/akHdMWQkuMRq2318kk1w2byezzuceKr9R2xTZRVc+ePR+2oxLrICDPye2AQ+eRhJDPKmas9jqvs3aVvVfOm1hfGuk3kuXdQPS1wU8SFz7+pGe9TRjsyCzm56OCWWjalWWrDli2wSItvDDTTm9iOiAuWX7K8hl+1Ud9oW4= ARC-Authentication-Results: i=2; server2.sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 2C4AD146149; Fri, 26 Jul 2024 17:39:07 +0000 (UTC) Received: from pdx1-sub0-mail-a208.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B0A72146094; Fri, 26 Jul 2024 17:39:06 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1722015546; a=rsa-sha256; cv=none; b=ir9JDkNrf02FevBzz7cPbM+8ARcZC3+PXUawNxbx7vUCE4Jp1mWyki2Ew8gm+t0bpRkJhK 0M+HcwekSardsZCM4Wyf51XJYbNN5GWxTKf56/EghsqGXk/PcNSehf1cFGxTbO3AfMjINc DvK+2IUtcHJb8IdUq444toiutq5Gy59GUhGOuCbp98uhOv3moW0HuB3lNyrE27h7eY07i9 MqDZYlm9pOGClcWybEotGE31wvS74XFfWwpWbkDc2Jg7skq7+ASboYY7jOGd+sNgEyC9NT Bqnbq88zb2SFZo1EvCBStIIM87cR2JY8VDshpCG2FAHtAQK4m4HCSHezBzLxig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1722015546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tuC1zas9tsyx/SkFkyNm1eOyAju9uS5HfK9FdLpudag=; b=auf7ilq9mo0gvXO/NkHqJxIQSHFy6h1wbt3Pk/Mw0SaXBPHUR0SPtkPZ2THeLpNdlxWG5I 7sR1+7oCurUrXcyY3ngdQ5NUBrR7cyhQ3VwSc8HZ/pKXORKS7AjRAG6h6ExPL9UQfns+Fw SNMCFz7AdXJXZ1Uhz8ce/eLdkldURZ5mxjagL8joIZxZhioA+FF2r7/sA4ZnnggMP9F+kW HevjFTv9tamd+iBSwmb1FTKJjSo9eQX2DxoKM2GY3pLXP/35FeihWLV/p9EboAQVMBDIQB r7VY7vAKafIiIOdShbjQeuU98vj8ZR6h1wu5CN98kMdWYYMIwJa6uX5L3u2AXQ== ARC-Authentication-Results: i=1; rspamd-7f77fccf7d-tnb9w; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Rock-Desert: 65d789fa30c36ea4_1722015547022_1120194730 X-MC-Loop-Signature: 1722015547022:1639668595 X-MC-Ingress-Time: 1722015547022 Received: from pdx1-sub0-mail-a208.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.116.25.171 (trex/7.0.2); Fri, 26 Jul 2024 17:39:07 +0000 Received: from [192.168.0.182] (unknown [184.146.171.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a208.dreamhost.com (Postfix) with ESMTPSA id 4WVw3Z2bMMz7x; Fri, 26 Jul 2024 10:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1722015546; bh=tuC1zas9tsyx/SkFkyNm1eOyAju9uS5HfK9FdLpudag=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=tt1TnetYPnrAmoKtltEfQuIQiBRUUQuQxWwOt40Wpct0y7281aT8iEVYStn7No6Yr lntAPkKsquALCh3eJVKAtjxM8gQJATEVpuGrC40ES66aIT4oYgeYYeixTjPJGntDQ9 ApiwKFQ0emp9+eYzr9N3DT2On8mZEWhnU+szo0qbMUT0iZYsNm9xvJsAQN1Tw4X8+g LMCUmK7ElJI4O/Wooz0px+8OyZtI+eOy9JiCrgjeefvaps7nTYf9eUiR/fCn6JUNKr 0uABFgu+CS4SY++9x06Gla3Rw58bqkVBD8TjSYKaqqLdj4cHkjes1215a9OBBziAOj oYg7/RtKKc0PQ== Message-ID: <862b3a6b-20c5-41dd-95c3-9fab2debd164@gotplt.org> Date: Fri, 26 Jul 2024 13:39:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gimple-ssa-sprintf: Fix typo in range check To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20240725234838.3804003-1-siddhesh@gotplt.org> Content-Language: en-US From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3029.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2024-07-26 13:11, Jakub Jelinek wrote: > On Thu, Jul 25, 2024 at 07:48:38PM -0400, Siddhesh Poyarekar wrote: >> The code to scale ranges for wide chars in format_string incorrectly >> checks range.likely to scale range.unlikely, which is a copy-paste typo >> from the immediate previous condition. >> >> gcc/ChangeLog: >> >> gimple-ssa-sprintf.cc (format_string): Fix type in range check >> for UNLIKELY for wide chars. >> >> Signed-off-by: Siddhesh Poyarekar > > LGTM. Thanks, pushed. > What exactly the code really wants to do is unclear to me, what does > the INT_MAX on the target have to do with the minimum/maximum/expected > sizes of %S or %ls printed strings is unclear, target PTRDIFF_MAX I think that is because the printf family returns the number of bytes/chars written in an int, which imposes the INT_MAX limitation on the format string expansion. > maybe. And why it uses this > if (slen.range.something < target_int_max ()) > slen.range.something *= something_else; > rather than say > slen.range.something > = MIN (slang.range.something * something_else, target_int_max ()); > perhaps with some overflow checking is also something that is hard to guess. That's what I tried first but I settled for the minimal change because I didn't want to dig in deeper than I had time for to at the moment. Further down it checks if MAX and UNLIKELY cross INT_MAX and then resets to INT_MAX, but that looks suspicious on, e.g. 32-bit targets. The code could use some refactoring/cleanup. Thanks, Sid