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.133.124]) by sourceware.org (Postfix) with ESMTPS id 03852389367D for ; Mon, 10 Jan 2022 10:37:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03852389367D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-62-zC13ZWp_NQOolDDym814Aw-1; Mon, 10 Jan 2022 05:37:35 -0500 X-MC-Unique: zC13ZWp_NQOolDDym814Aw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6760036393; Mon, 10 Jan 2022 10:37:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09FDF7CAF4; Mon, 10 Jan 2022 10:37:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 20AAbVjA1088257 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 10 Jan 2022 11:37:31 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20AAbUWQ1088256; Mon, 10 Jan 2022 11:37:30 +0100 Date: Mon, 10 Jan 2022 11:37:30 +0100 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH v5 1/4] tree-object-size: Support dynamic sizes in conditions Message-ID: <20220110103730.GD2646553@tucnak> Reply-To: Jakub Jelinek References: <20211109190137.1107736-1-siddhesh@gotplt.org> <20211218123511.139456-1-siddhesh@gotplt.org> <20211218123511.139456-2-siddhesh@gotplt.org> MIME-Version: 1.0 In-Reply-To: <20211218123511.139456-2-siddhesh@gotplt.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2022 10:37:38 -0000 On Sat, Dec 18, 2021 at 06:05:08PM +0530, Siddhesh Poyarekar wrote: Sorry for the delay. > +size_t > +__attribute__ ((noinline)) > +test_builtin_calloc_condphi (size_t cnt, size_t sz, int cond) > +{ > + struct > + { > + int a; > + char b; > + } bin[cnt]; > + > + char *ch = __builtin_calloc (cnt, sz); > + size_t ret = __builtin_dynamic_object_size (cond ? ch : (void *) &bin, 0); > + > + __builtin_free (ch); > + return ret; > +} > +int > +main (int argc, char **argv) You don't use argc nor argv, just leave those out IMO. > +{ > + if (test_builtin_malloc_condphi (1) != 32) > + FAIL (); > + if (test_builtin_malloc_condphi (0) != 64) > + FAIL (); You test the above with both possibilities. > + if (test_builtin_calloc_condphi (128, 1, 0) == 128) > + FAIL (); But not this one, why? Also, it would be better to have a != ... test rather than ==, if it is the VLA, then 128 * sizeof (struct { int a; char b; }) ? > +/* Return true if VAL is represents an initial size for OBJECT_SIZE_TYPE. */ s/is // > + > +static inline bool > +size_initval_p (tree val, int object_size_type) > + phires = TREE_VEC_ELT (size, TREE_VEC_LENGTH (size) - 1); > + gphi *phi = create_phi_node (phires, gimple_bb (stmt)); > + gphi *obj_phi = as_a (stmt); Formatting, just one space before as_a. > + /* Expand all size expressions to put their definitions close to the objects > + for whom size is being computed. */ English is not my primary language, but shouldn't whom be used just when talking about persons? So for which size instead? > > +static void > +dynamic_object_size (struct object_size_info *osi, tree var, > + tree *size, tree *wholesize) Missing function comment. > + if (i < num_args) > + sizes = wholesizes = size_unknown (object_size_type); Perhaps ggc_free (sizes); gcc_free (wholesizes); here before the assignment? > + > + /* Point to the same TREE_VEC so that we can avoid emitting two PHI > + nodes. */ > + if (!wholesize_needed) and make this else if > + wholesizes = sizes; and ggc_free (wholesizes); before the assignment? When it is very easy and provably correct that it will just be memory to be GCed later... Otherwise LGTM. Jakub