From patchwork Mon Feb 17 12:16:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1239179 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-519634-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz 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=Z9ug0Jof; 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 48Ljdc5P3xz9sRL for ; Mon, 17 Feb 2020 23:16:34 +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 :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=n6XzJNidgqnwgoYChku4rW863zeaeX0h3b6DOh2R7KikNoMHr1 GGYfB//B3fj5sCtPfOxZO5oJNS0ODV+Y2NIODo0FrJXYnhLZv+6Gbh4e8iVa/QWU HNdvXI0PcMR/OAxqfAHY2Vc3IRdB8JR4RffT4e6aL/Jsv8FxX63CP6OG8= 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 :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=bXKLyvIhLdq5sMSB3so6BxwjZ+s=; b=Z9ug0Jofplug+UP7BZwW wJSGCqlsOZTHTQRUGgljhPId5U8lvEYI50vx++SGIqn1DAceDHcy7T7TZVBUX6Zi rNYKjSneNhOBcWQaL5loCqvpiy7UOeO6lMy9W5/l4wB8NODpFPcViw/3kbvrrGtM kQ8d5MYeS1O896/WrhW8UO0= Received: (qmail 119323 invoked by alias); 17 Feb 2020 12:16:27 -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 119310 invoked by uid 89); 17 Feb 2020 12:16:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Feb 2020 12:16:25 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EA9E7B039; Mon, 17 Feb 2020 12:16:22 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Drop MALLOC attribute for void functions. To: gcc-patches@gcc.gnu.org Cc: Martin Jambor , Richard Biener , Jan Hubicka Message-ID: Date: Mon, 17 Feb 2020 13:16:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 X-IsSubscribed: yes Hello. As mentioned in the PR, we end up with a void function call that has set MALLOC attribute. That causes problems in RTL expansion. I believe a proper fix is to drop the attribute when a callgraph clone with void type is created. I would like to see Martin's comment about the hunk in propagate_malloc which is maybe suboptimal and one can find a better way? Patch can bootstrap on x86_64-linux-gnu and survives regression tests. It fixes LTO bootstrap on ppc64le. Thanks, Martin gcc/ChangeLog: 2020-02-17 Martin Liska PR ipa/93583 * cgraph.c (cgraph_node::verify_node): Verify MALLOC attribute and return type of functions. * ipa-param-manipulation.c (ipa_param_adjustments::adjust_decl): Drop MALLOC attribute for void functions. * ipa-pure-const.c (propagate_malloc): Do not set malloc flag for void functions. gcc/testsuite/ChangeLog: 2020-02-17 Martin Liska PR ipa/93583 * gcc.dg/ipa/pr93583.c: New test. --- gcc/cgraph.c | 6 ++++++ gcc/ipa-param-manipulation.c | 4 ++++ gcc/ipa-pure-const.c | 9 ++++++--- gcc/testsuite/gcc.dg/ipa/pr93583.c | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr93583.c diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 294b2d392fd..6e99fbb45f4 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -3374,6 +3374,12 @@ cgraph_node::verify_node (void) error ("calls_comdat_local is set outside of a comdat group"); error_found = true; } + if (DECL_IS_MALLOC (decl) + && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) + { + error ("MALLOC attribute set on a void function"); + error_found = true; + } for (e = indirect_calls; e; e = e->next_callee) { if (e->aux) diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 19ec87358fa..5f6f0575b06 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -410,6 +410,10 @@ ipa_param_adjustments::adjust_decl (tree orig_decl) DECL_VIRTUAL_P (new_decl) = 0; DECL_LANG_SPECIFIC (new_decl) = NULL; + /* Drop MALLOC attribute for a void function. */ + if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (new_decl)))) + DECL_IS_MALLOC (new_decl) = 0; + return new_decl; } diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index ccd0918c120..315134d2a94 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -1973,9 +1973,12 @@ propagate_malloc (void) node->dump_name ()); bool malloc_decl_p = DECL_IS_MALLOC (node->decl); - node->set_malloc_flag (true); - if (!malloc_decl_p && warn_suggest_attribute_malloc) - warn_function_malloc (node->decl); + if (!VOID_TYPE_P (TREE_TYPE (TREE_TYPE (node->decl)))) + { + node->set_malloc_flag (true); + if (!malloc_decl_p && warn_suggest_attribute_malloc) + warn_function_malloc (node->decl); + } } } diff --git a/gcc/testsuite/gcc.dg/ipa/pr93583.c b/gcc/testsuite/gcc.dg/ipa/pr93583.c new file mode 100644 index 00000000000..30ef506553d --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr93583.c @@ -0,0 +1,15 @@ +/* PR ipa/93583 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void *bar(const char*); +static void *__attribute__((malloc,noinline)) foo(const char *p) +{ + return bar (p); +} + +int main(int argc, char **argv) +{ + foo (argv[0]); + return 0; +}