[Bug c/120354] Flexible array union in the middle is not reported by -Wflex-array-member-not-at-end option when flexible array member is not the last one

2025-05-30 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120354

--- Comment #4 from GCC Commits  ---
The master branch has been updated by Qing Zhao :

https://gcc.gnu.org/g:70418e6c0120cfce33ab69628602dfdadbed683a

commit r16-1018-g70418e6c0120cfce33ab69628602dfdadbed683a
Author: Qing Zhao 
Date:   Thu May 29 15:59:41 2025 +

C: Flex array in union followed by a structure field is not reported
[PR120354]

There is only one last_field for a structure type, but there might
be multiple last_fields for a union type, therefore we should ORed
the result of TYPE_INCLUDES_FLEXARRAY for multiple last_fields of
a union type.

PR c/120354

gcc/c/ChangeLog:

* c-decl.cc (finish_struct): Or the results for
TYPE_INCLUDES_FLEXARRAY.

gcc/testsuite/ChangeLog:

* gcc.dg/pr120354.c: New test.

[Bug c/120354] Flexible array union in the middle is not reported by -Wflex-array-member-not-at-end option when flexible array member is not the last one

2025-05-27 Thread qinzhao at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120354

qinzhao at gcc dot gnu.org changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2025-05-27
 Status|UNCONFIRMED |ASSIGNED

[Bug c/120354] Flexible array union in the middle is not reported by -Wflex-array-member-not-at-end option when flexible array member is not the last one

2025-05-27 Thread qinzhao at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120354

--- Comment #3 from qinzhao at gcc dot gnu.org ---
(In reply to Ella Ma from comment #2)
> Sorry, I made a mistake when making the example.
> This problem happens when the flex-array member is not the last, **and the
> members below it are in a record type**. (GCC will report if they are in
> integer types)
> 
> Which means, in the original example, the `y` elements in `union X` and
> `union Y` should be in a struct or union (it is also not reported even if
> the struct or union is empty), rather than `int`.
> 
> Details and comparison with Clang in https://godbolt.org/z/zjPY9z5E7, please
> ignore the previous link to godbolt.

Yes, I can repeat this issue.

[Bug c/120354] Flexible array union in the middle is not reported by -Wflex-array-member-not-at-end option when flexible array member is not the last one

2025-05-22 Thread alansnape3058 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120354

--- Comment #2 from Ella Ma  ---
Sorry, I made a mistake when making the example.
This problem happens when the flex-array member is not the last, **and the
members below it are in a record type**. (GCC will report if they are in
integer types)

Which means, in the original example, the `y` elements in `union X` and `union
Y` should be in a struct or union (it is also not reported even if the struct
or union is empty), rather than `int`.

Details and comparison with Clang in https://godbolt.org/z/zjPY9z5E7, please
ignore the previous link to godbolt.

[Bug c/120354] Flexible array union in the middle is not reported by -Wflex-array-member-not-at-end option when flexible array member is not the last one

2025-05-19 Thread alansnape3058 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120354

--- Comment #1 from Ella Ma  ---
Details and comparison with Clang in https://godbolt.org/z/h8qYhK6rY