From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from iguana.tulip.relay.mailchannels.net (iguana.tulip.relay.mailchannels.net [23.83.218.253]) by sourceware.org (Postfix) with ESMTPS id E1A0038582B2 for ; Thu, 22 Sep 2022 15:26:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1A0038582B2 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 923D03E0C4D; Thu, 22 Sep 2022 15:26:36 +0000 (UTC) Received: from pdx1-sub0-mail-a307 (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 40C3B3E0CF1; Thu, 22 Sep 2022 15:26:34 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1663860396; a=rsa-sha256; cv=none; b=tyqAq4SIiObLfcHDhYR95/CDvSlxujjZGyypxMLys5BdhiRIQIC1BF0ORNWdglg0m1JR7R ucTsOCWhFsmbEHrwqWMNBYEW2GgO0UQyYMPWJRtUt0VEejeOz9ZLHHiGGFinQZBruw3v5N lwlGCQfGob/6/WWM+EBc/yoA00atbJMpIFM5kBmicCbsjbr1AFgCMva+6ytUXzTnOjSyZ8 YVopY5Bp8Otlor9p7vEpB5inZlEx419TPpFizSak4uy/NNfBpmHBb3PV8j0jX6xr0o9yxA LOzSs+bAidHzPXQtPSO94sy/SIz7ClJrA6BYmqUawmorqMgquDU2SRlpJpqjNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1663860396; 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=DtgWwomy9eRFJScM4eoeYnCLLci/EpbtMuVION4tV2Q=; b=wIYDHdBwocwq3v8G39hAE549+B8QN0GEgAPA2W6dJeRH+gEtSM+CMF5qZcHb643fCbIgIC d4zC2yiVo3pqENGojZH6eXoFqJzjv1JxTElX6BUWDPSkEn27rNwg4+U197Up0hqn/PzEV0 7qtlvu0BJsQaoCj2PrQLsuurzJ78YXNxmfKnYNMSK+8DV3QRBNwMa1CvqpnCittIRZODIz PGd37sYtyfjzrLJL1l6gpyF11rze+f0W8WI8LJdlWWDsNtY1VuvgB1K+fYxiuD4P2QihEn OG0trmHjx+tcbEtXWCfe6pZbcEjX7+y+6GPIektYJ+YpcFcrITeWCJ5YbXrE7A== ARC-Authentication-Results: i=1; rspamd-f776c45b8-2q8n5; 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-Chief-Lyrical: 1f058a8e34494444_1663860396321_842490427 X-MC-Loop-Signature: 1663860396321:1237360305 X-MC-Ingress-Time: 1663860396321 Received: from pdx1-sub0-mail-a307 (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.144.146 (trex/6.7.1); Thu, 22 Sep 2022 15:26:36 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-16-184-147-84-238.dsl.bell.ca [184.147.84.238]) (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-a307 (Postfix) with ESMTPSA id 4MYJzC72pTz54; Thu, 22 Sep 2022 08:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1663860392; bh=DtgWwomy9eRFJScM4eoeYnCLLci/EpbtMuVION4tV2Q=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=fKABnoUrlIlHIbqRX9SpHRjL2Mc89i6XYMrnP2h436clhDrTf0K6DTiH+bUrQ3mOp oqz2TaYnePDd3Vb+2LzofiSiln49TU65/mPAH/tQwVyNmZ9weF1pfQ9KybiXZMMTdK q4Wq7c856Pro5Rhu2+e4GM6qm8FkVAWkx+Kph0LD4pOV+281JNtmEXm67q9c57HNJC u6VVSF5F2jmHoEIzuWA+dfUR4hztmXC9hL+JvPURR0gWaABPmPkyatM7+zEiDyKjtR 1jAHbFykA64h4hjrdJnjfYKlCZ4qRwn39qVA9vJjHVXq2j3gS+EzjsA8L8vKgEaL/q V9ciezs1cPHtQ== Message-ID: Date: Thu, 22 Sep 2022 11:26:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] tree-object-size: Support strndup and strdup Content-Language: en-US To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20220815192311.763473-1-siddhesh@gotplt.org> From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3032.7 required=5.0 tests=BAYES_00,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-09-22 09:02, Jakub Jelinek wrote: > On Mon, Aug 15, 2022 at 03:23:11PM -0400, Siddhesh Poyarekar wrote: >> --- a/gcc/tree-object-size.cc >> +++ b/gcc/tree-object-size.cc >> @@ -495,6 +495,18 @@ decl_init_size (tree decl, bool min) >> return size; >> } >> >> +/* Get the outermost object that PTR may point into. */ >> + >> +static tree >> +get_whole_object (const_tree ptr) >> +{ >> + tree pt_var = TREE_OPERAND (ptr, 0); >> + while (handled_component_p (pt_var)) >> + pt_var = TREE_OPERAND (pt_var, 0); >> + >> + return pt_var; >> +} > > Not sure why you want a new function for this. > This is essentially get_base_address (TREE_OPERAND (ptr, 0)). Oh, so can addr_object_size be simplified to use get_base_address too? >> /* Compute __builtin_object_size for PTR, which is a ADDR_EXPR. >> OBJECT_SIZE_TYPE is the second argument from __builtin_object_size. >> If unknown, return size_unknown (object_size_type). */ >> + if (!size_valid_p (sz, object_size_type) >> + || size_unknown_p (sz, object_size_type)) >> + { >> + tree wholesrc = NULL_TREE; >> + if (TREE_CODE (src) == ADDR_EXPR) >> + wholesrc = get_whole_object (src); >> + >> + if (!(object_size_type & OST_MINIMUM) >> + || (wholesrc && TREE_CODE (wholesrc) == STRING_CST)) > > Is this safe? I mean get_whole_object will also skip ARRAY_REFs with > variable indexes etc. and the STRING_CST could have embedded '\0's > in it. > Even if c_strlen (src, 1) is constant, I don't see what you can assume > for object size of strndup ("abcd\0efgh", n); for minimum, except 1. Can't we assume MIN(5, n) for STRING_CST? For ARRAY_REFs, it may end up being MIN(array_size, n) and not account for the NUL termination but I was thinking of that as being a better option than bailing out. Should we try harder here and return, e.g. strlen or some equivalent? > But on the other side, 1 is a safe minimum for OST_MINIMUM of both > strdup and strndup if you don't find anything more specific (exact strlen > for strndup) because the terminating '\0' will be always there. OK, I can return size_one_node as the final return value for OST_MINIMUM if we don't find a suitable expression. > Other than that you'd need to consider INTEGER_CST second strndup argument > or ranges of the second argument etc. > E.g. maximum for OST_DYNAMIC could be for strndup (src, n) > MIN (__bdos (src, ?), n + 1). Yeah, that's what I return in the end: return fold_build2 (MIN_EXPR, sizetype, fold_build2 (PLUS_EXPR, sizetype, size_one_node,n), sz); where sz is __bdos(src) > >> @@ -2113,7 +2177,7 @@ const pass_data pass_data_object_sizes = >> PROP_objsz, /* properties_provided */ >> 0, /* properties_destroyed */ >> 0, /* todo_flags_start */ >> - 0, /* todo_flags_finish */ >> + TODO_update_ssa_no_phi, /* todo_flags_finish */ >> }; >> >> class pass_object_sizes : public gimple_opt_pass >> @@ -2153,7 +2217,7 @@ const pass_data pass_data_early_object_sizes = >> 0, /* properties_provided */ >> 0, /* properties_destroyed */ >> 0, /* todo_flags_start */ >> - 0, /* todo_flags_finish */ >> + TODO_update_ssa_no_phi, /* todo_flags_finish */ >> }; > > This is quite expensive. Do you really need full ssa update, or just > TODO_update_ssa_only_virtuals would be enough (is it for the missing > vuse on the strlen call if you emit it)? > In any case, would be better not to do that always, but only if you > really need it (emitted the strlen call somewhere; e.g. if __bdos is > never used, only __bos, it is certainly not needed), todo flags > can be both in todo_flags_finish and in return value from execute method. Thanks, I'll find a cheaper way to do this. Thanks, Sid