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 2844E3858401 for ; Thu, 2 Feb 2023 08:33:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2844E3858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0FB7634180; Thu, 2 Feb 2023 08:33:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1675326801; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MRs+hxyC6yiEqWsuo9VnefxAy5uXiyzzc6JPeOdPcYA=; b=cnb1NgeQd//ASTv8c5SrBx+yq3JGggnYprNhAcDunQmiY/zqCsX1Gku472YuJ6dY94n1iU 9wxYb9H5nPw6jov+MaWH9P5FVHkEo16ze7876J4S7eWvpboU370MhEJWr426MRVNE3IMT4 /U/xLQgKdG5gaWF6EsyJGFL+/G22UsY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1675326801; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MRs+hxyC6yiEqWsuo9VnefxAy5uXiyzzc6JPeOdPcYA=; b=vM3YrEdAa+5rOgJqYjGQe7ITOkpNVFj33YxPirJEN4KsnjeB8xi5bR5FEgCy5M4QwIFTeQ Okf+Egg+QR7k94BQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (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 0A7472C142; Thu, 2 Feb 2023 08:33:19 +0000 (UTC) Date: Thu, 2 Feb 2023 08:33:19 +0000 (UTC) From: Richard Biener To: Siddhesh Poyarekar cc: Qing Zhao , gcc Patches , "keescook@chromium.org" , "Joseph S. Myers" Subject: Re: [PATCH 2/2] Documentation Update. In-Reply-To: Message-ID: References: <20230131141140.3610133-1-qing.zhao@oracle.com> <20230131141140.3610133-3-qing.zhao@oracle.com> <1AB22124-10D2-416D-B1BD-D4FF728AB0E2@oracle.com> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.1 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 1 Feb 2023, Siddhesh Poyarekar wrote: > On 2023-02-01 13:24, Qing Zhao wrote: > > > > > >> On Feb 1, 2023, at 11:55 AM, Siddhesh Poyarekar > >> wrote: > >> > >> On 2023-01-31 09:11, Qing Zhao wrote: > >>> Update documentation to clarify a GCC extension on structure with > >>> flexible array member being nested in another structure. > >>> gcc/ChangeLog: > >>> * doc/extend.texi: Document GCC extension on a structure containing > >>> a flexible array member to be a member of another structure. > >> > >> Should this resolve pr#77650 since the proposed action there appears to be > >> to document these semantics? > > > > My understanding of pr77650 is specifically for documentation on the > > following case: > > > > The structure with a flexible array member is the middle field of another > > structure. > > > > Which I added in the documentation as the 2nd situation. > > However, I am still not very comfortable on my current clarification on this > > situation: how should we document on > > the expected gcc behavior to handle such situation? > > I reckon wording that dissuades programmers from using this might be > appropriate, i.e. don't rely on this and if you already have such nested flex > arrays, change code to remove them. > > >>> +In the above, @code{flex_data.data[]} is allowed to be extended flexibly > >>> to > >>> +the padding. E.g, up to 4 elements. > > """ > ... Relying on space in struct padding is bad programming practice and any > code relying on this behaviour should be modified to ensure that flexible > array members only end up at the ends of arrays. The `-pedantic` flag should > help identify such uses. > """ > > Although -pedantic will also flag on flex arrays nested in structs even if > they're at the end of the parent struct, so my suggestion on the warning is > not really perfect. Wow, so I checked and we indeed accept struct X { int n; int data[]; }; struct Y { struct X x; int end; }; and -pedantic says t.c:2:21: warning: invalid use of structure with flexible array member [-Wpedantic] 2 | struct Y { struct X x; int end; }; | and clang reports t.c:2:21: warning: field 'x' with variable sized type 'struct X' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end] struct Y { struct X x; int end; }; ^ looking at PR77650 what seems missing there is the semantics of this extension as expected/required by the glibc use. comment#5 seems to suggest that for my example above its expected that Y.x.data[0] aliases Y.end?! There must be a better way to write the glibc code and IMHO it would be best to deprecate this extension. Definitely the middle-end wouldn't consider this aliasing for my example - maybe it "works" when wrapped inside a union but then for sure only when the union is visible in all accesses ... typedef union { struct __gconv_info __cd; struct { struct __gconv_info __cd; struct __gconv_step_data __data; } __combined; } _G_iconv_t; could be written as typedef union { struct __gconv_info __cd; char __dummy[sizeof(struct __gconv_info) + sizeof(struct __gconv_step_data)]; } _G_iconv_t; in case the intent is to provide a complete type with space for a single __gconv_step_data. Richard.