* Any changes in C23's aliasing rules (or a gcc problem?)
@ 2023-10-19 15:36 Georg-Johann Lay
2023-10-19 20:06 ` Alexander Monakov
0 siblings, 1 reply; 2+ messages in thread
From: Georg-Johann Lay @ 2023-10-19 15:36 UTC (permalink / raw)
To: gcc-help
Just came across the following test case
#include <stdio.h>
int main (void)
{
float a = -248.75;
printf ("%f\n", a);
unsigned char* ptr = (unsigned char*) &a;
for (size_t i = 0; i < sizeof (a); i++)
{
printf ("%.2X ", ptr[i]);
}
}
Compiled with gcc v13.2 (or master) and -O3 -std=c2x.
The for loop prints "00 00 00 00" which is because "a"
is not written to the frame, but read in the loop thus garbage.
With -fno-strict-aliasing, output is "00 C0 78 C3" as expected.
https://godbolt.org/z/GMcez7M95
What am I missing?
Johann
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Any changes in C23's aliasing rules (or a gcc problem?)
2023-10-19 15:36 Any changes in C23's aliasing rules (or a gcc problem?) Georg-Johann Lay
@ 2023-10-19 20:06 ` Alexander Monakov
0 siblings, 0 replies; 2+ messages in thread
From: Alexander Monakov @ 2023-10-19 20:06 UTC (permalink / raw)
To: Georg-Johann Lay; +Cc: gcc-help
On Thu, 19 Oct 2023, Georg-Johann Lay wrote:
> Just came across the following test case
>
> #include <stdio.h>
>
> int main (void)
> {
> float a = -248.75;
> printf ("%f\n", a);
>
> unsigned char* ptr = (unsigned char*) &a;
> for (size_t i = 0; i < sizeof (a); i++)
> {
> printf ("%.2X ", ptr[i]);
> }
> }
>
> Compiled with gcc v13.2 (or master) and -O3 -std=c2x.
>
> The for loop prints "00 00 00 00" which is because "a"
> is not written to the frame, but read in the loop thus garbage.
>
> With -fno-strict-aliasing, output is "00 C0 78 C3" as expected.
>
> https://godbolt.org/z/GMcez7M95
>
> What am I missing?
Nice catch, I've filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111884
Alexander
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-19 20:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 15:36 Any changes in C23's aliasing rules (or a gcc problem?) Georg-Johann Lay
2023-10-19 20:06 ` Alexander Monakov
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).