From patchwork Fri Feb 19 13:20:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1442169 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DhsdQ36pyz9sBy for ; Sat, 20 Feb 2021 00:20:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60FC8398B87C; Fri, 19 Feb 2021 13:20:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 2EC5A398B82B for ; Fri, 19 Feb 2021 13:20:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2EC5A398B82B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0B476ABAE for ; Fri, 19 Feb 2021 13:20:19 +0000 (UTC) Date: Fri, 19 Feb 2021 14:20:18 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/99122 - more VLA inlining fixes Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This avoids declaring a function with VLA arguments or return values as inlineable. IPA CP still ICEs, so the testcase has that disabled. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-02-19 Richard Biener PR middle-end/99122 * tree-inline.c (inline_forbidden_p): Do not inline functions with VLA arguments or return value. * gcc.dg/pr99122-3.c: New testcase. --- gcc/testsuite/gcc.dg/pr99122-3.c | 19 +++++++++++++++++++ gcc/tree-inline.c | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr99122-3.c diff --git a/gcc/testsuite/gcc.dg/pr99122-3.c b/gcc/testsuite/gcc.dg/pr99122-3.c new file mode 100644 index 00000000000..6aa5b2912ca --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr99122-3.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g -fno-ipa-cp -w" } */ + +static int foo (); + +int +bar (int n) +{ + return foo (n, 2.0); +} + +static inline int +foo (int n, struct T { char a[n]; } b) +{ + int r = 0, i; + for (i = 0; i < n; i++) + r += b.a[i]; + return r; +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 01a08cf27be..c993b1fee8a 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -4022,6 +4022,16 @@ inline_forbidden_p (tree fndecl) wi.info = (void *) fndecl; wi.pset = &visited_nodes; + /* We cannot inline a function with a VLA typed argument or result since + we have no implementation materializing a variable of such type in + the caller. */ + if (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))) + && !poly_int_tree_p (TYPE_SIZE (TREE_TYPE (TREE_TYPE (fndecl))))) + return true; + for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) + if (!poly_int_tree_p (DECL_SIZE (parm))) + return true; + FOR_EACH_BB_FN (bb, fun) { gimple *ret;