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 ESMTP id D171A3858D26 for ; Fri, 26 Jul 2024 18:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D171A3858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D171A3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722017985; cv=none; b=rvG5bJqukdFvgxsgjNq6k37q/ZwD+aTZT+uJOJO+kRrlG3jnPnmtEBujIas56gfwd2dZfHBuEVQM/cHE2tHAoWroviAtVreSzXOTlZMsmLNX8W3AXE8neoZ6SougJx0hYSa/fIqIv5g3OxTgwCPPh9qqEAPooJKoDwrv4XyMdNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722017985; c=relaxed/simple; bh=R82PjDxqJVZZKDaDOLSeMZ0oB9e4dRlc7uAzPicf298=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=RnUMH16F2PiCOce8KgVZieaaSBR0/NnZsCzGUczEAoPOzi7d0/ddCZEm8scFhLmVlx+r0UTGVnu+3jq2XSO7hmPq8h4/Qsg/OCWw30VBNQQLdCF8wvuYtU6aHikzCuR/trr21PW5XcY03SjFY+nBEvt3AcCHBq6do/sWlYMY+IE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722017979; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=V7ZPvUvHnq0tjqAdAkbsBzc02hB8QKUO1lakbdgPuMY=; b=Ba4KwiWpsdHfjGWcj9PDlzMCaGOEiSlbIK9liSMfx0nqGRC4ACUqeqMZ2Yz/FnvV5hDbqX vPteKi2DsxYCQyXndtVgeJe4vMHYFEGffIrWNmNBcijEFwb+13fIc+NhnL8YuInIKHxfKP evOu6IwwfutXxY1x2Z/4gybJfDvnzNA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-GmZcfAmwNICXKiGbKkwD1g-1; Fri, 26 Jul 2024 14:19:37 -0400 X-MC-Unique: GmZcfAmwNICXKiGbKkwD1g-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93C2419560AB; Fri, 26 Jul 2024 18:19:31 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CF0CA1955F3B; Fri, 26 Jul 2024 18:19:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 46QIJQ0X2171634 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 26 Jul 2024 20:19:26 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 46QIJPfd2171633; Fri, 26 Jul 2024 20:19:25 +0200 Date: Fri, 26 Jul 2024 20:19:25 +0200 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] gimple-ssa-sprintf: Fix typo in range check Message-ID: Reply-To: Jakub Jelinek References: <20240725234838.3804003-1-siddhesh@gotplt.org> <862b3a6b-20c5-41dd-95c3-9fab2debd164@gotplt.org> MIME-Version: 1.0 In-Reply-To: <862b3a6b-20c5-41dd-95c3-9fab2debd164@gotplt.org> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 Fri, Jul 26, 2024 at 01:39:04PM -0400, Siddhesh Poyarekar wrote: > > 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. Ah, yes, that makes sense. > > 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. I think the counters are HOST_WIDE_INT or unsigned HOST_WIDE_INT, so always 64-bit. Jakub