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 8FE103894C3A for ; Mon, 10 Jan 2022 10:50:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8FE103894C3A 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-482-e2aqrYjTOWOuyPvx8c7FEw-1; Mon, 10 Jan 2022 05:50:28 -0500 X-MC-Unique: e2aqrYjTOWOuyPvx8c7FEw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0944B1006AA5; Mon, 10 Jan 2022 10:50:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B080081F5B; Mon, 10 Jan 2022 10:50:27 +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 20AAoPr91088309 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 10 Jan 2022 11:50:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20AAoOje1088308; Mon, 10 Jan 2022 11:50:24 +0100 Date: Mon, 10 Jan 2022 11:50:24 +0100 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH v5 2/4] tree-object-size: Handle function parameters Message-ID: <20220110105024.GE2646553@tucnak> Reply-To: Jakub Jelinek References: <20211109190137.1107736-1-siddhesh@gotplt.org> <20211218123511.139456-1-siddhesh@gotplt.org> <20211218123511.139456-3-siddhesh@gotplt.org> MIME-Version: 1.0 In-Reply-To: <20211218123511.139456-3-siddhesh@gotplt.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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:50:31 -0000 On Sat, Dec 18, 2021 at 06:05:09PM +0530, Siddhesh Poyarekar wrote: > @@ -1440,6 +1441,53 @@ cond_expr_object_size (struct object_size_info *osi, tree var, gimple *stmt) > return reexamine; > } > > +/* Find size of an object passed as a parameter to the function. */ > + > +static void > +parm_object_size (struct object_size_info *osi, tree var) > +{ > + int object_size_type = osi->object_size_type; > + tree parm = SSA_NAME_VAR (var); > + > + if (!(object_size_type & OST_DYNAMIC) || !POINTER_TYPE_P (TREE_TYPE (parm))) > + expr_object_size (osi, var, parm); This looks very suspicious. Didn't you mean { expr_object_size (...); return; } here? Because the code below e.g. certainly assumes OST_DYNAMIC and that TREE_TYPE (parm) is a pointer type (otherwise TREE_TYPE (TREE_TYPE (...) wouldn't work. > + > + /* Look for access attribute. */ > + rdwr_map rdwr_idx; > + > + tree fndecl = cfun->decl; > + const attr_access *access = get_parm_access (rdwr_idx, parm, fndecl); > + tree typesize = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (parm))); > + tree sz = NULL_TREE; > + > + if (access && access->sizarg != UINT_MAX) Perhaps && typesize here? It makes no sense to e.g. create ssa default def when you aren't going to use it in any way. > + { > + tree fnargs = DECL_ARGUMENTS (fndecl); > + tree arg = NULL_TREE; > + unsigned argpos = 0; > + > + /* Walk through the parameters to pick the size parameter and safely > + scale it by the type size. */ > + for (arg = fnargs; argpos != access->sizarg && arg; > + arg = TREE_CHAIN (arg), ++argpos); Instead of a loop with empty body wouldn't it be better to do the work in that for loop? I.e. take argpos != access->sizarg && from the condition, replace arg != NULL_TREE with that argpos == access->sizarg and add a break;? > + > + if (arg != NULL_TREE && INTEGRAL_TYPE_P (TREE_TYPE (arg))) > + { > + sz = get_or_create_ssa_default_def (cfun, arg); Also, I must say I'm little bit worried about this get_or_create_ssa_default_def call. If the SSA_NAME doesn't exist, so you create it and then attempt to use it but in the end don't because e.g. some PHI's another argument was unknown etc., will that SSA_NAME be released through release_ssa_name? I think GIMPLE is fairly unhappy if there are SSA_NAMEs created and not released that don't appear in the IL anywhere. > + if (sz != NULL_TREE) > + { > + sz = fold_convert (sizetype, sz); > + if (typesize) > + sz = size_binop (MULT_EXPR, sz, typesize); > + } > + } > + } Jakub