Re: Any changes in C23's aliasing rules (or a gcc problem?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux