From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from purple.birch.relay.mailchannels.net (purple.birch.relay.mailchannels.net [23.83.209.150]) by sourceware.org (Postfix) with ESMTPS id AB3833853D4D for ; Mon, 21 Nov 2022 14:27:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB3833853D4D 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 61E3E3C22D1; Mon, 21 Nov 2022 14:27:39 +0000 (UTC) Received: from pdx1-sub0-mail-a304.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 00C803C25C7; Mon, 21 Nov 2022 14:27:37 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1669040858; a=rsa-sha256; cv=none; b=xdAbvBUxb9q3ue0c/q7VoU0lydhbgIIup5q3WMZ+kVOl3tcflh1EHsG+LkW0Hj9u3+bvUL N09d0wK5RGJqCGwSqSU91hlTGgktym1lSVVxOb++wWozkIDTmXxLUUBQj26IW6Sr4pKYQk k8Wvy+omXUqzIe48EtPXhftY9REcN4NS0a3ySNKCD+H/kpZzbxfNttFteuuxnPa2LuHYxR dsAhhJF7gCm29UEbheqkKNQXkZOeomyiCea5azEFOxQgn59/ZO8279OhDDf77dt7Wd/ruX txf+1IvTP1E0mvTiwDgrj08XqfX+UptXcXblHYApxH2t2codi0e+xtyyqlLLBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1669040858; 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=wWUrrMarWpnvLlYCj+6D7dONmQ4QYMQ7B3QTxXJZAFY=; b=0xKgN70+nsD6tIKcQnBJX+j5ERGlxivTOzFfYH9J7iK3SjTez7LhCI++9VDmSYfdPIH6eQ kUefC55vPJzjNRBCu2VFZm4RFicpjIGAmlPls1DEvRVSkrpiwtHq0fWEy+QcE7rKR5f64c hOjJ4ToV7UJnkzAvmc+Fwz1y7k1jCbaH4SpBWOc4nZW7S7vbHrzouqsahqFeQbIDw/iNtk Ix6pZe2xFiIcRDL9ZL5Uva5rA/rhgt+M8gq7VSdVbvNC2UEaXVu/XwtoQdsRNBi5C32gxf 018+hEribIQNJe7/rs3uSKa8cNF5Yq37k6WLtZcvS+BWW1pwYac2Zw3zsdvzog== ARC-Authentication-Results: i=1; rspamd-64c57ffbcf-f5dqj; 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-Minister-Illustrious: 7cdc968c301bc3c6_1669040858261_4159273313 X-MC-Loop-Signature: 1669040858261:1341183191 X-MC-Ingress-Time: 1669040858261 Received: from pdx1-sub0-mail-a304.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.196.246 (trex/6.7.1); Mon, 21 Nov 2022 14:27:38 +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-a304.dreamhost.com (Postfix) with ESMTPSA id 4NG8qY2qhsz22; Mon, 21 Nov 2022 06:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1669040857; bh=wWUrrMarWpnvLlYCj+6D7dONmQ4QYMQ7B3QTxXJZAFY=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=VPsZvG7Q57hDl9Zg88p5zZJWwzyZ3zyWasmaBto4En9zKEJO0JE3jW3xkM2Xnhqfl pbFUDY3xitM+PusCzPZdz3NH9MHLiHa7M/1Ld03yuBO7fb6aVyTLkigi2dFh4GNuIA fJGL+++BE9Jax/FjbChiUalavnuKNCTAuq8ELVw2zTLLV8uRMSJ+jg5DRwENWNHzMm R5ZPzZsfea35mcNK/QcTSKhKFNVBhCC1cwYEwuCoJFyH5mOpTyKwU+Gj4yakqqYQ4z w3OKCYIjj+l1vrNsA2DrfyTlTRlkenmz7ksle5D45NQcanCQfpXxKBNyMdk0uQc5/B P42IY02sfE3oA== Message-ID: <90c74d8b-6dd9-49f3-ae83-ee97edb21b0f@gotplt.org> Date: Mon, 21 Nov 2022 09:27:36 -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> 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.8 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-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. Thanks, Sid