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 B5D1B3858C60 for ; Tue, 17 Aug 2021 08:29:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B5D1B3858C60 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id ABDB321ECD; Tue, 17 Aug 2021 08:29:54 +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 A1CD8A3B81; Tue, 17 Aug 2021 08:29:54 +0000 (UTC) Date: Tue, 17 Aug 2021 10:29:54 +0200 (CEST) From: Richard Biener To: Qing Zhao cc: Martin Jambor , Jakub Jelinek , Kees Cook , Nick Alcock via Gcc-patches , Richard Biener Subject: Re: [patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc In-Reply-To: <8B2F93E8-C3AC-49D2-B764-D4DD8A150A52@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> 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: Tue, 17 Aug 2021 08:30:06 -0000 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) > /* If this is a VLA or the variable is not in register, > expand to a memset to initialize it. */ > tree var_addr = NULL_TREE; > if (is_vla) > var_addr = TREE_OPERAND (lhs, 0); > else > { > TREE_ADDRESSABLE (lhs) = 1; > var_addr = build_fold_addr_expr (lhs); > } use, independent of is_vla mark_addressable (lhs); var_addr = build_fold_addr_expr (lhs); > > tree value = (init_type == AUTO_INIT_PATTERN) ? > build_int_cst (unsigned_char_type_node, > INIT_PATTERN_VALUE) : > build_zero_cst (unsigned_char_type_node); since memset has an integer argument for the value use integer_zero_node for the zero case and build_int_cst (integer_type_node, ...) for the pattern case > tree m_call = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMSET), > 3, var_addr, value, var_size); > /* Expand this memset call. */ > expand_builtin_memset (m_call, NULL_RTX, TYPE_MODE (var_type)); > } > else > { > /* If this variable is in a register, use expand_assignment might > generate better code. */ > tree pattern = NULL_TREE; > unsigned HOST_WIDE_INT total_bytes > = tree_to_uhwi (TYPE_SIZE_UNIT (var_type)); > > if (init_type == AUTO_INIT_PATTERN) > { > if (can_native_interpret_type_p (var_type)) > { > unsigned char *buf = (unsigned char *) xmalloc (total_bytes); > memset (buf, INIT_PATTERN_VALUE, total_bytes); > pattern = native_interpret_expr (var_type, buf, total_bytes); > gcc_assert (pattern); > } > else > { > tree index_type = build_index_type (size_int (total_bytes - 1)); > tree array_type = build_array_type (unsigned_char_type_node, > index_type); > tree element = build_int_cst (unsigned_char_type_node, > INIT_PATTERN_VALUE); > vec *elts = NULL; > for (unsigned int i = 0; i < total_bytes; i++) > CONSTRUCTOR_APPEND_ELT (elts, NULL_TREE, element); > pattern = build_constructor (array_type, elts); > pattern = build1 (VIEW_CONVERT_EXPR, var_type, pattern); > } > } > > tree init = (init_type == AUTO_INIT_PATTERN) ? > pattern : > build_zero_cst (var_type); maybe conditionally initialize init instead of pattern and init? Thus replace pattern by init and do else init = build_zero_cst (var_type); the above should work, as said the RTL expansion part can possibly be improved but we can do this as followup as well. > expand_assignment (lhs, init, false); > } > } > > Thanks. > > Qing > > > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)