public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-53548-4-zvCDIguKO2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-53548-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53548

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Qing Zhao <qinzhao@gcc.gnu.org>:

https://gcc.gnu.org/g:adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a

commit r15-208-gadb1c8a0f167c3a1f7593d75f5a10eb07a5d741a
Author: Qing Zhao <qing.zhao@oracle.com>
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=53548

    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 introduced
    -fstrict-flex-arrays=n to gradually eliminate the "fake flexible array"
    usages from C/C++ source code. As a result, zero-length arrays eventually
    will be replaced by C99 flexiable array member completely.

    Therefore, GCC needs to explicitly allow such extensions directly for C99
    flexible arrays, since flexable array member in unions or alone in structs
    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 without
    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.

  parent reply	other threads:[~2024-05-06 18:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01  2:13 [Bug c/53548] New: " vapier at gentoo dot org
2012-06-04  0:50 ` [Bug c/53548] " carlos_odonell at mentor dot com
2024-03-08 20:41 ` kees at outflux dot net
2024-03-08 20:42 ` kees at outflux dot net
2024-03-08 20:50 ` kees at outflux dot net
2024-03-13 19:34 ` qinzhao at gcc dot gnu.org
2024-04-08 18:20 ` qinzhao at gcc dot gnu.org
2024-05-06 18:36 ` cvs-commit at gcc dot gnu.org [this message]
2024-05-06 18:36 ` cvs-commit at gcc dot gnu.org
2024-05-06 18:36 ` cvs-commit at gcc dot gnu.org
2024-05-06 18:36 ` cvs-commit at gcc dot gnu.org
2024-05-06 18:40 ` qinzhao at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53548-4-zvCDIguKO2@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).