From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id EB6B33858403 for ; Fri, 10 Sep 2021 10:37:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB6B33858403 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B9E5D223A1; Fri, 10 Sep 2021 10:37:52 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9BB2713D29; Fri, 10 Sep 2021 10:37:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id G77kJIA1O2HbFwAAMHmgww (envelope-from ); Fri, 10 Sep 2021 10:37:52 +0000 Date: Fri, 10 Sep 2021 12:37:52 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: qing.zhao@oracle.com, keescook@chromium.org Subject: [PATCH] middle-end/102273 - avoid ICE with auto-init and nested functions Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Fri, 10 Sep 2021 10:37:55 -0000 This refactors expansion to consider non-decl LHS. I suspect the is_val argument is not needed. Bootstrapped and regtest running on x86_64-unknown-linux-gnu. Richard. 2021-09-10 Richard Biener PR middle-end/102273 * internal-fn.c (expand_DEFERRED_INIT): Always expand non-SSA vars. * gcc.dg/pr102273.c: New testcase. --- gcc/internal-fn.c | 22 +++++++--------------- gcc/testsuite/gcc.dg/pr102273.c | 11 +++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr102273.c diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index ada2a820ff1..b1283690080 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3006,31 +3006,23 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) tree var_size = gimple_call_arg (stmt, 0); enum auto_init_type init_type = (enum auto_init_type) TREE_INT_CST_LOW (gimple_call_arg (stmt, 1)); - bool is_vla = (bool) TREE_INT_CST_LOW (gimple_call_arg (stmt, 2)); bool reg_lhs = true; tree var_type = TREE_TYPE (lhs); gcc_assert (init_type > AUTO_INIT_UNINITIALIZED); - if (DECL_P (lhs)) - { - rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); - reg_lhs = !MEM_P (tem); - } - else if (TREE_CODE (lhs) == SSA_NAME) + if (TREE_CODE (lhs) == SSA_NAME) reg_lhs = true; else { - gcc_assert (is_vla); - reg_lhs = false; + rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); + reg_lhs = !MEM_P (tem); } - if (!reg_lhs) { - /* If this is a VLA or the variable is not in register, - expand to a memset to initialize it. */ - + /* If this is a VLA or the variable is not in register, + expand to a memset to initialize it. */ mark_addressable (lhs); tree var_addr = build_fold_addr_expr (lhs); @@ -3045,8 +3037,8 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) } else { - /* If this variable is in a register, use expand_assignment might - generate better code. */ + /* If this variable is in a register, use expand_assignment might + generate better code. */ tree init = build_zero_cst (var_type); unsigned HOST_WIDE_INT total_bytes = tree_to_uhwi (TYPE_SIZE_UNIT (var_type)); diff --git a/gcc/testsuite/gcc.dg/pr102273.c b/gcc/testsuite/gcc.dg/pr102273.c new file mode 100644 index 00000000000..568e44ebfef --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102273.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-ftrivial-auto-var-init=zero" } */ + +void bar(); + +struct A { char d; }; +void foo() +{ + struct A e; + void baz() { bar(e); } +} -- 2.31.1