diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2024-05-06 16:25:04 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2024-05-06 18:30:46 +0000 |
commit | adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a (patch) | |
tree | 0466efa1b9e5f281fdf34c9acfa5cd4588121721 /gcc/c | |
parent | 08e752e72363ae7fd5a5fcb70913a0f7b240387b (diff) | |
download | gcc-adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a.zip gcc-adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a.tar.gz gcc-adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a.tar.bz2 |
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.
Diffstat (limited to 'gcc/c')
0 files changed, 0 insertions, 0 deletions