From patchwork Tue Jan 28 02:09:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1230123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=jyZM+WU1; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Pdt0uJDd; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48696s4f4sz9sP3 for ; Tue, 28 Jan 2020 13:09:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=tPnFdrKS0y69l7H+dshdUPE+vSyeoEwmTusyyynHdavyJ5KOkTJLq P4Gf2AiScgUq/XC6tKTH9V2q6c00zxovmdii35k37EFUrykhvmG8D79cvHcBYcYr 8Ske9CC/cg9/HzHpI8FNYgbIyC2nYw/KReJB7wfl35eZGYI/x4lb+s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=alRn2ZLL8s0J7qHORqkvxZHFO7U=; b=jyZM+WU1FTg4ju6iNNfPSqex31TY cGCPoRVRm9texqov6+vwYxkV2SMoW86dCHZxN6FgSJwCgkIKz0WBgobtwPLHirSV XW8VrQgzAfo24XaG9GYWJ8wynEgn9l1xWwfo4MzvAfQybtr1u9NMggDu9nt8jZN6 srB5NzMS8aCEX/g= Received: (qmail 100275 invoked by alias); 28 Jan 2020 02:09:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 99127 invoked by uid 89); 28 Jan 2020 02:09:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Jan 2020 02:09:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580177384; 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; bh=CM4a0SwB/4N8VEy3mWJA6aero8Sf4V03kA7v/c7F9EQ=; b=Pdt0uJDdR7meek8s2QdXv4qLtR1ifmOgjZ0aUmEch2Ar3tPlfhMnn9OsYwdU2bZ8E96Rln fSqUfxBe4jxbE6gwQKUZYajc/W4QHhreGcKWx1hMY0GnGjAn3gaTEL/ms01541V6/yNJPa 6r13eP5lq97i2+4zJViUUrJWiyhGQ1Y= 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-400-LPLtqSAePMW-Jghzb-5hjw-1; Mon, 27 Jan 2020 21:09:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6772610054E3 for ; Tue, 28 Jan 2020 02:09:41 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF97C87034; Tue, 28 Jan 2020 02:09:40 +0000 (UTC) From: David Malcolm To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, David Malcolm Subject: [PATCH] calls.c: refactor special_function_p for use by analyzer Date: Mon, 27 Jan 2020 21:09:37 -0500 Message-Id: <20200128020937.18455-1-dmalcolm@redhat.com> In-Reply-To: <20200122194002.GQ10088@tucnak> References: <20200122194002.GQ10088@tucnak> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes On Wed, 2020-01-22 at 20:40 +0100, Jakub Jelinek wrote: > On Wed, Jan 22, 2020 at 02:35:13PM -0500, David Malcolm wrote: > > PR analyzer/93316 reports various testsuite failures where I > > accidentally relied on properties of x86_64-pc-linux-gnu. > > > > The following patch fixes them on sparc-sun-solaris2.11 (gcc211 in > > the > > GCC compile farm), and, I hope, the other configurations showing > > failures. > > > > There may still be other failures for pattern-test-2.c, which I'm > > tracking separately as PR analyzer/93291. > > > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; > > tested on stage 1 on sparc-sun-solaris2.11. > > > > gcc/analyzer/ChangeLog: > > PR analyzer/93316 > > * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as > > "_setjmp". > > Please see calls.c (special_function_p), you should treat certainly > also sigsetjmp as a setjmp call, and similarly to special_function_p, > skip over _ or __ prefixes before the setjmp or sigsetjmp name. > Similarly for longjmp/siglongjmp. > > Jakub This patch refactors some code in special_function_p that checks for the function being sane to match by name, splitting it out into a new maybe_special_function_p, and using it it two places in the analyzer. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; OK for master? Thanks Dave gcc/analyzer/ChangeLog: * analyzer.cc (is_named_call_p): Replace tests for fndecl being extern at file scope and having a non-NULL DECL_NAME with a call to maybe_special_function_p. * function-set.cc (function_set::contains_decl_p): Add call to maybe_special_function_p. gcc/ChangeLog: * calls.c (maybe_special_function_p): New function, splitting out the check for DECL_NAME being non-NULL and fndecl being extern at file scope from... (special_function_p): ...here. Drop check for fndecl being non-NULL that was after a usage of DECL_NAME (fndecl). * tree.h (maybe_special_function_p): New decl. --- gcc/analyzer/analyzer.cc | 10 +-------- gcc/analyzer/function-set.cc | 2 ++ gcc/calls.c | 40 +++++++++++++++++++++++++----------- gcc/tree.h | 2 ++ 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 1b5e4c9ecf8..5cf745ea632 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -65,18 +65,10 @@ is_named_call_p (tree fndecl, const char *funcname) gcc_assert (fndecl); gcc_assert (funcname); - /* Exclude functions not at the file scope, or not `extern', - since they are not the magic functions we would otherwise - think they are. */ - if (!((DECL_CONTEXT (fndecl) == NULL_TREE - || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL) - && TREE_PUBLIC (fndecl))) + if (!maybe_special_function_p (fndecl)) return false; tree identifier = DECL_NAME (fndecl); - if (identifier == NULL) - return false; - const char *name = IDENTIFIER_POINTER (identifier); const char *tname = name; diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc index 6ed15ae95ad..1b6b5d9f9c1 100644 --- a/gcc/analyzer/function-set.cc +++ b/gcc/analyzer/function-set.cc @@ -59,6 +59,8 @@ bool function_set::contains_decl_p (tree fndecl) const { gcc_assert (fndecl && DECL_P (fndecl)); + if (!maybe_special_function_p (fndecl)) + return false; return contains_name_p (IDENTIFIER_POINTER (DECL_NAME (fndecl))); } diff --git a/gcc/calls.c b/gcc/calls.c index 1336f49ea5e..447a36c3707 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -572,22 +572,18 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU anti_adjust_stack (gen_int_mode (n_popped, Pmode)); } -/* Determine if the function identified by FNDECL is one with - special properties we wish to know about. Modify FLAGS accordingly. - - For example, if the function might return more than one time (setjmp), then - set ECF_RETURNS_TWICE. +/* Determine if the function identified by FNDECL is one that + makes sense to match by name, for those places where we detect + "magic" functions by name. - Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate - space from the stack such as alloca. */ + Return true if FNDECL has a name and is an extern fndecl at file scope. + FNDECL must be a non-NULL decl. */ -static int -special_function_p (const_tree fndecl, int flags) +bool +maybe_special_function_p (const_tree fndecl) { tree name_decl = DECL_NAME (fndecl); - - if (fndecl && name_decl - && IDENTIFIER_LENGTH (name_decl) <= 11 + if (name_decl /* Exclude functions not at the file scope, or not `extern', since they are not the magic functions we would otherwise think they are. @@ -598,6 +594,26 @@ special_function_p (const_tree fndecl, int flags) && (DECL_CONTEXT (fndecl) == NULL_TREE || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL) && TREE_PUBLIC (fndecl)) + return true; + return false; +} + +/* Determine if the function identified by FNDECL is one with + special properties we wish to know about. Modify FLAGS accordingly. + + For example, if the function might return more than one time (setjmp), then + set ECF_RETURNS_TWICE. + + Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate + space from the stack such as alloca. */ + +static int +special_function_p (const_tree fndecl, int flags) +{ + tree name_decl = DECL_NAME (fndecl); + + if (maybe_special_function_p (fndecl) + && IDENTIFIER_LENGTH (name_decl) <= 11) { const char *name = IDENTIFIER_POINTER (name_decl); const char *tname = name; diff --git a/gcc/tree.h b/gcc/tree.h index 93422206b63..b7db69267c2 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5611,6 +5611,8 @@ builtin_decl_declared_p (enum built_in_function fncode) && builtin_info[uns_fncode].declared_p); } +extern bool maybe_special_function_p (const_tree fndecl); + /* Return true if T (assumed to be a DECL) is a global variable. A variable is considered global if its storage is not automatic. */