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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 545B83846079 for ; Fri, 12 Mar 2021 14:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 545B83846079 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-OhORzcvuMoCnDko9VOO5EA-1; Fri, 12 Mar 2021 09:04:36 -0500 X-MC-Unique: OhORzcvuMoCnDko9VOO5EA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5923D107ACCA; Fri, 12 Mar 2021 14:04:35 +0000 (UTC) Received: from t14s.localdomain (ovpn-114-98.phx2.redhat.com [10.3.114.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id C618E19744; Fri, 12 Mar 2021 14:04:34 +0000 (UTC) Message-ID: Subject: Re: [PATCH] avoid assuming gimple_call_alloc_size argument is a call (PR 99489) From: David Malcolm To: Jakub Jelinek , Martin Sebor Cc: gcc-patches Date: Fri, 12 Mar 2021 09:04:33 -0500 In-Reply-To: <20210312135220.GW745611@tucnak> References: <20210312135220.GW745611@tucnak> User-Agent: Evolution 3.38.3 (3.38.3-1.fc33) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Fri, 12 Mar 2021 14:04:39 -0000 On Fri, 2021-03-12 at 14:52 +0100, Jakub Jelinek via Gcc-patches wrote: > On Tue, Mar 09, 2021 at 03:07:38PM -0700, Martin Sebor via Gcc- > patches wrote: > > The gimple_call_alloc_size() function is documented to "return null > > when STMT is not a call to a valid allocation function" but the > > code > > assumes STMT is a call statement, causing the function to ICE when > > it isn't. > > > > The attached patch changes the function to fulfill its contract and > > return null also when STMT isn't a call.  The fix seems obvious to > > me but I'll wait some time before committing it in case it's not > > to someone else. > > I think the name of the function suggests that it should be called on > calls, > not random stmts.  Currently the function has 3 callers, two of them > already verify is_gimple_call before calling it and only one doesn't, > and the stmt will never be NULL. > So I'd say it would be better to remove the if (!stmt) return > NULL_TREE; > from the start of the function and add is_gimple_call (stmt) && > in tree-ssa-strlen.c. Maybe even make it convert it to taking a "const gcall *", so those if (is_gimple_call (stmt)) { ... if (gimple_call_alloc_size (stmt, ...)) { } } become: if (const gcall *call = dyn_cast (stmt)) { ... if (gimple_call_alloc_size (call, ...)) { } } so that the compiler can enforce this requirement via the type system? Hope this is constructive Dave