From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fish.tulip.relay.mailchannels.net (fish.tulip.relay.mailchannels.net [23.83.218.251]) by sourceware.org (Postfix) with ESMTPS id 3CE4D384603C for ; Tue, 22 Nov 2022 23:13:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3CE4D384603C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.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 3E93B502153; Tue, 22 Nov 2022 23:13:43 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id BC609501FCB; Tue, 22 Nov 2022 23:13:42 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1669158822; a=rsa-sha256; cv=none; b=l/Wz7+dJ7LmjeXVzvB8fJHWi4M/SKgvPs9NkEYYS6VMXZhh6QlMd5rn5wziSgJOp4DM/b1 wD91qk41ZXsvmVrOdZ8iDr6nt2fpWAh/gG5cogPDqYpDxGcayARC6bZ3Lu1N0UhFMWiNqh XTc1uiCui92glaFdxPn3qFUPsRG4nAChNJBi20rwrieGXCVNOYcRmguoKOXO78S7P7Hpj5 7Vjx9Q+sb3QwiYVwyHVx+ifWcCsD3FIcoSgVnzfzl+/Dy6jvNqc7WDeTyBfRAMX3MDg2yh OiH3IhMkfGARD3/dOrY7MTZk1TCCSmSonDzuEUWDKPT7bSPc7/iO4WqbWjALDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1669158822; 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=gSqZkFIwoLmYwA4/GO4nM9tFApJ7LH0YjnfCNFgjGho=; b=l9FWRvWzOKlqX/aRsDNvEOYePg5C2cGH6S89e/yW5QMuQpnszmQubmNvINCeZ/4cxEsaN3 7wCGqd9hmdErwTb1D2GMgaJp24uGcp4D6a37K/Cny96ElGD0stLsi7LS3BS516JezNBBCs G/estcBCn+bowIMSAxKdXboGteKEzqijVQ6WWK+tvY5deRM73rYGJSv/R3Z4Dj4geylxXQ ckeftKOoqH48aOfw/Aa0Ky6bfTCRV/vNUrcq0SPsryy9jwnVpdjtyXFAs4b8ZZm+hMrvvR EpVE5E55wXDw3wrYdYOmF9Y8M+BLtQrX3Ys2ZfgbXCpWncuLcec5cPovw/x1oA== ARC-Authentication-Results: i=1; rspamd-64c57ffbcf-p85hk; 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-Spill-Gusty: 3a2d154b0fbb43c2_1669158823021_811874601 X-MC-Loop-Signature: 1669158823020:2073229695 X-MC-Ingress-Time: 1669158823020 Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.200.83 (trex/6.7.1); Tue, 22 Nov 2022 23:13:43 +0000 Received: from [192.168.0.182] (bras-base-toroon4834w-grc-23-76-68-24-147.dsl.bell.ca [76.68.24.147]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4NH0S61l8bz52; Tue, 22 Nov 2022 15:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1669158822; bh=gSqZkFIwoLmYwA4/GO4nM9tFApJ7LH0YjnfCNFgjGho=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=VIifIHnlshnjBkT1UqQT6SB0kr0sUNSwKdIutknxr9Z8YgXM3izZQ/04pkoysvuQR rIw1bJTFLHaYGVwCp0TEqobvSpCP5CwSTWuMqwMF7xDR7PDagkxhzCwSl7HLNBzFvz ZHWyFxenpzDFYaqJJZZUiK3vhS7RLyKfzgVF8RqkeuZZqkHTmC+OeYWENl3c74fkP5 uYuVsmRH45NZVJYhl1jD5iUQ1q7p0yfd4jIv4eAuLhrGaD9mhaAS/Q6qVdoghMlIak wWVJl/sUmV+1VsNSM+6RnY4RRfqNACFIaCXYGu+NvOt+sRUjfYHzZtpPH3AYYgiBPX AxLxxowGP84gg== Message-ID: <6f7c019b-d940-f2a6-3db0-21486fb0e6a2@gotplt.org> Date: Tue, 22 Nov 2022 18:13:40 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2] tree-object-size: Support strndup and strdup Content-Language: en-US To: Jeff Law , gcc-patches@gcc.gnu.org Cc: jakub@redhat.com References: <20220815192311.763473-1-siddhesh@gotplt.org> <20221104124800.910588-1-siddhesh@gotplt.org> <90c74d8b-6dd9-49f3-ae83-ee97edb21b0f@gotplt.org> From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3029.6 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 2022-11-22 15:43, Jeff Law wrote: > > On 11/21/22 07:27, Siddhesh Poyarekar wrote: >> On 2022-11-20 10:42, Jeff Law wrote: >>> >>> On 11/4/22 06:48, Siddhesh Poyarekar wrote: >>>> Use string length of input to strdup to determine the usable size of >>>> the >>>> resulting object.  Avoid doing the same for strndup since there's a >>>> chance that the input may be too large, resulting in an unnecessary >>>> overhead or worse, the input may not be NULL terminated, resulting in a >>>> crash where there would otherwise have been none. >>>> >>>> gcc/ChangeLog: >>>> >>>>     * tree-object-size.cc (todo): New variable. >>>>     (object_sizes_execute): Use it. >>>>     (strdup_object_size): New function. >>>>     (call_object_size): Use it. >>>> >>>> gcc/testsuite/ChangeLog: >>>> >>>>     * gcc.dg/builtin-dynamic-object-size-0.c (test_strdup, >>>>     test_strndup, test_strdup_min, test_strndup_min): New tests. >>>>     (main): Call them. >>>>     * gcc.dg/builtin-dynamic-object-size-1.c: Silence overread >>>>     warnings. >>>>     * gcc.dg/builtin-dynamic-object-size-2.c: Likewise. >>>>     * gcc.dg/builtin-dynamic-object-size-3.c: Likewise. >>>>     * gcc.dg/builtin-dynamic-object-size-4.c: Likewise. >>>>     * gcc.dg/builtin-object-size-1.c: Silence overread warnings. >>>>     Declare free, strdup and strndup. >>>>     (test11): New test. >>>>     (main): Call it. >>>>     * gcc.dg/builtin-object-size-2.c: Silence overread warnings. >>>>     Declare free, strdup and strndup. >>>>     (test9): New test. >>>>     (main): Call it. >>>>     * gcc.dg/builtin-object-size-3.c: Silence overread warnings. >>>>     Declare free, strdup and strndup. >>>>     (test11): New test. >>>>     (main): Call it. >>>>     * gcc.dg/builtin-object-size-4.c: Silence overread warnings. >>>>     Declare free, strdup and strndup. >>>>     (test9): New test. >>>>     (main): Call it. >>> >>> I'm struggling to see how the SSA updating is correct.  Yes we need >>> to update the virtuals due to the introduction of the call to strlen, >>> particularly when SRC is not a string constant.  But do we need to do >>> more? >>> >>> Don't we end up gimplifying the 1 + strlenfn (src) expression? Can >>> that possibly create new SSA_NAMEs?  Do those need to be put into SSA >>> form? I feel like I'm missing something here... >> >> We do all of that manually in gimplify_size_expressions, the only >> thing left to do is updating virtuals AFAICT. > > I guess it's actually buried down in force_gimple_operand and I guess > for temporaries they're not going to be alive across the new gimple > sequence and each destination gets its own SSA_NAME, so it ought to be > safe.  Just had to work a bit further through things. > > OK for the trunk. Thanks, pushed with the trivial fixup that Prathamesh suggested, i.e. replaced 'if (!strndup)' with 'else'. Sid