From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9B4DB3858433; Mon, 6 May 2024 18:36:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B4DB3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715020588; bh=hdXraKNAcwxvcRagJK1JQzyryDDyDKFZNFOPHem9dVY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WqN4vNVUWqwzQToAh1UTPY3jhLGt8WEY/I+T1qzJbJNbWYlzmQLjghMqdbOR2RIw1 ycmDReu7mYAP6994BcHX6FEYXohYVwz10ftSeZO3FOBD1cYF67dXpYFnMqK23AOMyT nc8eNtVOHD5USmzkfUYG0WpbHVTomj/oCN+UsVy0= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/53548] allow flexible array members in unions like zero-length arrays Date: Mon, 06 May 2024 18:36:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: qinzhao at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53548 --- Comment #11 from GCC Commits --- The master branch has been updated by Qing Zhao : https://gcc.gnu.org/g:adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a commit r15-208-gadb1c8a0f167c3a1f7593d75f5a10eb07a5d741a Author: Qing Zhao Date: Mon May 6 16:25:04 2024 +0000 Allow flexible array members in unions and alone in structures [PR53548] The request for GCC to accept that the C99 flexible array member can be in a union or alone in a structure has been made a long time ago around 2012 for supporting several practical cases including glibc. A GCC PR has been opened for such request at that time: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53548 However, this PR was closed as WONTFIX around 2015 due to the following reason: "there is an existing extension that makes the requested functionality possible" i.e GCC fully supported that the zero-length array can be in a union or alone in a structure for a long time. (though I didn't see any official documentation on such extension) It's reasonable to close PR53548 at that time since zero-length array extension can be used for such purpose. However, since GCC13, in order to improve the C/C++ security, we introd= uced -fstrict-flex-arrays=3Dn to gradually eliminate the "fake flexible arra= y" usages from C/C++ source code. As a result, zero-length arrays eventual= ly will be replaced by C99 flexiable array member completely. Therefore, GCC needs to explicitly allow such extensions directly for C= 99 flexible arrays, since flexable array member in unions or alone in stru= cts are common code patterns in active use by the Linux kernel (and other projects). For example, these do not error by default with GCC: union one { int a; int b[0]; }; union two { int a; struct { struct { } __empty; int b[]; }; }; But these do: union three { int a; int b[]; }; struct four { int b[]; } Clang has supported such extensions since March, 2024 https://github.com/llvm/llvm-project/pull/84428 GCC should also support such extensions. This will allow for a seamless transition for code bases away from zero-length arrays witho= ut losing existing code patterns. gcc/ChangeLog: PR c/53548 * doc/extend.texi: Add documentation for Flexible Array Members= in Unions and Flexible Array Members alone in Structures.=