From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 7070F3858409 for ; Thu, 19 Aug 2021 09:00:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7070F3858409 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 66E41200B2; Thu, 19 Aug 2021 09:00:10 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 00E09A3C14; Thu, 19 Aug 2021 09:00:04 +0000 (UTC) Date: Thu, 19 Aug 2021 11:00:10 +0200 (CEST) From: Richard Biener To: Qing Zhao cc: Jakub Jelinek , Nick Alcock via Gcc-patches , Kees Cook Subject: Re: [patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc In-Reply-To: <7AD092FB-62D6-4C87-B141-FD649E7B3F93@oracle.com> Message-ID: References: <52E29277-1403-4755-901A-528116C43FB8@oracle.com> <517EA40B-9500-4090-8F03-B4A9CECC62F8@oracle.com> <8B2F93E8-C3AC-49D2-B764-D4DD8A150A52@oracle.com> <786F370D-4A45-4F66-846C-A3437A162A65@oracle.com> <986D883E-A346-456A-B335-4185D4B136B5@oracle.com> <7AD092FB-62D6-4C87-B141-FD649E7B3F93@oracle.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Thu, 19 Aug 2021 09:00:22 -0000 On Wed, 18 Aug 2021, Qing Zhao wrote: > > > > On Aug 18, 2021, at 2:15 AM, Richard Biener wrote: > > > > On Tue, 17 Aug 2021, Qing Zhao wrote: > > > >> > >> > >>> On Aug 17, 2021, at 9:50 AM, Qing Zhao via Gcc-patches wrote: > >>> > >>> > >>> > >>>> On Aug 17, 2021, at 3:29 AM, Richard Biener wrote: > >>>> > >>>> On Mon, 16 Aug 2021, Qing Zhao wrote: > >>>> > >>>>> My current code for expand_DEFERRED_INIT is like the following, could you check and see whether there is any issue for it: > >>>>> > >>>>> #define INIT_PATTERN_VALUE 0xFE > >>>>> static void > >>>>> expand_DEFERRED_INIT (internal_fn, gcall *stmt) > >>>>> { > >>>>> tree lhs = gimple_call_lhs (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)); > >>>>> > >>>>> tree var_type = TREE_TYPE (lhs); > >>>>> gcc_assert (init_type > AUTO_INIT_UNINITIALIZED); > >>>>> > >>>>> if (is_vla || (!use_register_for_decl (lhs))) > >>>>> { > >>>>> if (TREE_CODE (lhs) == SSA_NAME) > >>>>> lhs = SSA_NAME_VAR (lhs); > >>>> > >>>> this should not be necessary (in fact you shouldn't see a SSA_NAME > >>>> here, if you do then using SSA_NAME_VAR is wrong) > >>> You mean during RTL expansion phase, all SSA_NAMEs are gone already? > >> > >> Actually, the lhs could be SSA_NAME here, > >> > >> Breakpoint 1, expand_DEFERRED_INIT (stmt=0x7fffe96ae348) at ../../latest-gcc/gcc/internal-fn.c:3021 > >> 3021 mark_addressable (lhs); > >> (gdb) call debug_tree(lhs) > >> >> type >> size > >> unit-size > >> align:32 warn_if_not_align:0 symtab:0 alias-set 2 canonical-type 0x7fffe959b2a0 precision:32 > >> pointer_to_this > > >> visited var > >> def_stmt temp1_5 = .DEFERRED_INIT (4, 2, 0, &"temp1"[0]); > >> version:5> > >> > >> when I deleted: > >> > >> if (TREE_CODE (lhs) == SSA_NAME > >> lhs = SSA_NAME_VAR (lhs); > > > > but then using SSA_NAME_VAR is broken. I suspect use_register_for_decl > > isn't the correct thing to look at. I think we need to look at what > > the LHS expanded to if it is a SSA_VAR_P (that includes SSA names > > but also plain DECLs but not what we get from VLAs where we'd see > > *ptr). So sth like > > > > bool reg_lhs; > > if (SSA_VAR_P (lhs)) > > { > > rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); > > reg_lhs = !MEM_P (tem); > > /* If not MEM_P reg_lhs should be REG_P or SUBREG_P (but maybe > > also CONCAT or lowpart...?) */ > > } > > else > > { > > gcc_assert (is_vla); > > reg_lhs = false; > > } > > > > if (!reg_lhs) > > memset path > > else > > expand_assignment path > > After making the following change: > > + bool reg_lhs = true; > > tree var_type = TREE_TYPE (lhs); > gcc_assert (init_type > AUTO_INIT_UNINITIALIZED); > > - if (is_vla || (!use_register_for_decl (lhs))) > + if (SSA_VAR_P (lhs)) > + { > + rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); > + reg_lhs = !MEM_P (tem); > + } > + else > + { > + gcc_assert (is_vla); > + reg_lhs = false; > + } > + > + if (!reg_lhs) > { > > I got exactly the same internal error that failed at expr.c: > > 8436 /* We must have made progress. */ > 8437 gcc_assert (inner != exp); > > > Looks like for the following code: > > 3026 if (!reg_lhs) > 3027 { > 3028 /* If this is a VLA or the variable is not in register, > 3029 expand to a memset to initialize it. */ > 3030 mark_addressable (lhs); > 3031 tree var_addr = build_fold_addr_expr (lhs); > 3032 > 3033 tree value = (init_type == AUTO_INIT_PATTERN) ? > 3034 build_int_cst (integer_type_node, > 3035 INIT_PATTERN_VALUE) : > 3036 integer_zero_node; > 3037 tree m_call = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMSET), > 3038 3, var_addr, value, var_size); > 3039 /* Expand this memset call. */ > 3040 expand_builtin_memset (m_call, NULL_RTX, TYPE_MODE (var_type)); > 3041 } > > At line 3030, “lhs” could be a SSA_NAME. > > My questions are: > > 1. Could the routine “mark_addressable” and “build_fold_addr_expr” be applied on SSA_NAME? No. > 2. Could the routine “expand_builtin_memset” be applied on the memset call whose “DEST” is > an address expression on SSA_NAME? No. > 3. Within “expand_DEFERRED_INIT”, can I call “expand_builtin_memset” to expand .DEFERRED_INIT? Well, not with "invalid" GENERIC I fear (address of a SSA name). > I suspect that one of the above 3 might be the issue, but not sure which one? All of the above ;) So while reg_lhs is now precise as to how the variable will end up (the SSA name will end up as a stack variable in this case, for whatever reason), expansion via memcpy only works when working on the RTL representation. The usual "workaround" (ugh) is to use make_tree (), so in the !reg_lhs path you'd do /* Get a new GENERIC representation for the RTL. That's necesary in case LHS is an SSA name. */ lhs = make_tree (TREE_TYPE (lhs), tem); alternatively you could maybe do 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) reg_lhs = true; else reg_lhs = false; thus treat SSA names as register storage always (even if it will end up on the stack). Richard. > Thanks a lot. > > Qing > > > > > bool reg_lhs; > > if (SSA_VAR_P (lhs)) > > { > > rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); > > reg_lhs = !MEM_P (tem); > > /* If not MEM_P reg_lhs should be REG_P or SUBREG_P (but maybe > > also CONCAT or lowpart...?) */ > > } > > else > > { > > gcc_assert (is_vla); > > reg_lhs = false; > > } > > > > > >> Many testing cases failed with internal compiler error: > >> > >> /home/opc/Work/GCC/latest-gcc/gcc/testsuite/c-c++-common/auto-init-3.c:9:9: internal compiler error: in expand_expr_addr_expr_1, at expr.c:8437 > >> 0xe237aa expand_expr_addr_expr_1 > >> ../../latest-gcc/gcc/expr.c:8437 > >> 0xe24059 expand_expr_addr_expr > >> ../../latest-gcc/gcc/expr.c:8525 > >> 0xe32b56 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) > >> ../../latest-gcc/gcc/expr.c:11741 > >> 0xe2da52 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) > >> ../../latest-gcc/gcc/expr.c:10777 > >> 0xe24706 expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) > >> ../../latest-gcc/gcc/expr.c:8713 > >> 0xc13f15 expand_expr > >> ../../latest-gcc/gcc/expr.h:301 > >> 0xc17acb get_memory_rtx > >> ../../latest-gcc/gcc/builtins.c:1370 > >> 0xc2223d expand_builtin_memset_args > >> ../../latest-gcc/gcc/builtins.c:4102 > >> 0xc21a20 expand_builtin_memset(tree_node*, rtx_def*, machine_mode) > >> ../../latest-gcc/gcc/builtins.c:3886 > >> 0xfb5c85 expand_DEFERRED_INIT > >> ../../latest-gcc/gcc/internal-fn.c:3031 > >> > >> > >> So, did I do anything wrong? > >> > >> Qing > > > > -- > > Richard Biener > > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, > > Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg) > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)