From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 768B33858D38 for ; Tue, 7 Feb 2023 19:41:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 768B33858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by gnu.wildebeest.org (Postfix, from userid 1000) id 845833000A21; Tue, 7 Feb 2023 20:41:22 +0100 (CET) Date: Tue, 7 Feb 2023 20:41:22 +0100 From: Mark Wielaard To: Ilya Leoshkevich Cc: elfutils-devel@sourceware.org Subject: Re: [PATCH RFC 02/11] libasm: Fix xdefault_pattern initialization Message-ID: <20230207194122.GC25444@gnu.wildebeest.org> References: <20230206222513.1773039-1-iii@linux.ibm.com> <20230206222513.1773039-3-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230206222513.1773039-3-iii@linux.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Ilya, On Mon, Feb 06, 2023 at 11:25:04PM +0100, Ilya Leoshkevich via Elfutils-devel wrote: > clang complains: > > asm_newscn.c:48:22: error: field 'pattern' with variable sized type 'struct FillPattern' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] > struct FillPattern pattern; > ^ > > Fix by using a union instead. Define the second union member to be a > char array 1 byte larger than struct FillPattern. This should be legal > according to 6.7.9: > > If an object that has static or thread storage duration is not > initialized explicitly, then ... if it is a union, the first named > member is initialized (recursively) according to these rules, and > any padding is initialized to zero bits. > > Signed-off-by: Ilya Leoshkevich > --- > libasm/asm_newscn.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/libasm/asm_newscn.c b/libasm/asm_newscn.c > index d258d969..32a3b598 100644 > --- a/libasm/asm_newscn.c > +++ b/libasm/asm_newscn.c > @@ -43,17 +43,16 @@ > /* Memory for the default pattern. The type uses a flexible array > which does work well with a static initializer. So we play some > dirty tricks here. */ > -static const struct > +static const union > { > struct FillPattern pattern; > - char zero; > + char zeroes[sizeof(struct FillPattern) + 1]; > } xdefault_pattern = > { > .pattern = > { > .len = 1 > }, > - .zero = '\0' > }; Yes, I think this works. Could you update the comment just before this with some of the commit message explanation? Your explanation is much better than "play some dirty trick" :) > const struct FillPattern *__libasm_default_pattern = &xdefault_pattern.pattern; I am surprised this doesn't need a cast. Do you know why? Thanks, Mark