public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113232] New: wrong code at -fpack-struct on x86_64-pc-linux-gnu
@ 2024-01-04 12:01 jwzeng at nuaa dot edu.cn
2024-01-04 15:01 ` [Bug c/113232] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2024-01-04 12:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113232
Bug ID: 113232
Summary: wrong code at -fpack-struct on x86_64-pc-linux-gnu
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jwzeng at nuaa dot edu.cn
Target Milestone: ---
I compiled the following code with gcc at -fpack-struct, and it produces the
wrong code.
The correct output result should be 0, but 2048 was output under -fpack-struct.
This bug seems to be a long-standing bug that exists on almost all gcc
versions.
Compiler explorer: https://godbolt.org/z/v4sq988P9
```c
$ cat test.c
int printf(const char *, ...);
struct a {
char b;
short c;
};
union {
short b;
struct a d;
} e;
int main() {
e.b = 0;
for (e.d.c = 0; e.d.c < 8; e.d.c++)
;
printf("%d\n", e.b);
}
$
$ gcc-tk test.c -O0; ./test.c
0
$ gcc-tk test.c -fpack-struct; ./test.c
2048
$ ccomp test.c -O0; ./a.out
0
$
$ gcc-tk --version
gcc (GCC) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
$ ccomp --version
The CompCert C verified compiler, version 3.12
```
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/113232] wrong code at -fpack-struct on x86_64-pc-linux-gnu
2024-01-04 12:01 [Bug c/113232] New: wrong code at -fpack-struct on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
@ 2024-01-04 15:01 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-04 15:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113232
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is not a bug.
Without -fpacked-struct, e.b and e.d.c does not have any bits in common due to
a padding field in `struct a` because of the alignment of short is 2. But with
-fpacked-struct, the padding byte/field goes away and you get an overlap.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-04 15:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 12:01 [Bug c/113232] New: wrong code at -fpack-struct on x86_64-pc-linux-gnu jwzeng at nuaa dot edu.cn
2024-01-04 15:01 ` [Bug c/113232] " pinskia 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).