public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/111775] New: -Wstrict-flex-arrays missing diagnostics with unions
@ 2023-10-11 19:39 crrodriguez at opensuse dot org
2024-06-14 14:50 ` [Bug middle-end/111775] " crrodriguez at opensuse dot org
2024-06-14 15:08 ` qinzhao at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: crrodriguez at opensuse dot org @ 2023-10-11 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111775
Bug ID: 111775
Summary: -Wstrict-flex-arrays missing diagnostics with unions
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: crrodriguez at opensuse dot org
Target Milestone: ---
following code is not diagnosed
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
struct foo {
int dum;
union {
/* or [1] */
char a[0];
wchar_t b[0];
} fn;
};
int main(void)
{
struct foo *f = malloc(sizeof(*f));
/* or really any use of the union does not matter */
printf("%p", f->fn.b);
free(f);
return 0;
}
compile options
-Wall -fstrict-flex-arrays -Werror=strict-flex-arrays -O2
This test is a silly mockup of real widespread code, which goes undiagnosed
until test suites run and/or is built with ubsan.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/111775] -Wstrict-flex-arrays missing diagnostics with unions
2023-10-11 19:39 [Bug middle-end/111775] New: -Wstrict-flex-arrays missing diagnostics with unions crrodriguez at opensuse dot org
@ 2024-06-14 14:50 ` crrodriguez at opensuse dot org
2024-06-14 15:08 ` qinzhao at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: crrodriguez at opensuse dot org @ 2024-06-14 14:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111775
--- Comment #1 from Cristian Rodríguez <crrodriguez at opensuse dot org> ---
Any hope of getting this fixed for 15? it is quite annoying when trying to
update older codebases to use c99 FAM.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/111775] -Wstrict-flex-arrays missing diagnostics with unions
2023-10-11 19:39 [Bug middle-end/111775] New: -Wstrict-flex-arrays missing diagnostics with unions crrodriguez at opensuse dot org
2024-06-14 14:50 ` [Bug middle-end/111775] " crrodriguez at opensuse dot org
@ 2024-06-14 15:08 ` qinzhao at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2024-06-14 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111775
--- Comment #2 from qinzhao at gcc dot gnu.org ---
(In reply to Cristian Rodríguez from comment #1)
> Any hope of getting this fixed for 15? it is quite annoying when trying to
> update older codebases to use c99 FAM.
a slightly modified source code will enable the -Wstrict-flex-arrays to report
the warning:
[opc@qinzhao-ol8u3-x86 111775]$ diff t.c t.c.org
18c18
< printf("%p", f->fn.b[0]);
---
> printf("%p", f->fn.b);
And with the following slightly modified testing case:
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
struct foo {
int dum;
char a[0];
};
int main(void)
{
struct foo *f = malloc(sizeof(*f));
/* or really any use of the union does not matter */
printf("%p", f->a);
free(f);
return 0;
}
-Wstrict-flex-arrays does not report the warning either.
so, this is not relating to union. It's relating to the reference to the array.
in your testing case, the reference f->fn.b didn't imply that this will be used
as an flexible array, so, -Wstrict-flex-arrays has no reason to report any
warning for this.
So, I don't think this is a bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-14 15:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11 19:39 [Bug middle-end/111775] New: -Wstrict-flex-arrays missing diagnostics with unions crrodriguez at opensuse dot org
2024-06-14 14:50 ` [Bug middle-end/111775] " crrodriguez at opensuse dot org
2024-06-14 15:08 ` qinzhao at gcc dot gnu.org
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).