https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58416

Alexander Cherepanov <ch3root at openwall dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ch3root at openwall dot com

--- Comment #5 from Alexander Cherepanov <ch3root at openwall dot com> ---
Not sure if it's still the same bug but the pattern from this PR leads to
problems with long double on x86-64. The optimization looses data in bytes
corresponding to padding in long double.

Transformation from a string to a long double is wrong too, filed separately --
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71475. But here this example is
only to illustrate that the padding is lost.

Source code:

----------------------------------------------------------------------
#include <stdio.h>

struct s {
  char s[sizeof(long double)];
};

union u {
  long double d;
  struct s s;
};

int main()
{
  union u x = {0};
  x.s = (struct s){"xxxxxxxxxxxxxxxx"};

  union u y = x;

  // start from the big end
  for (unsigned char *p = (unsigned char *)&y + sizeof y; p-- > (unsigned char
*)&y;)
    printf("%02x ", *p);
  puts("");
}
----------------------------------------------------------------------

Results:

----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 

$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
00 00 00 00 00 40 00 00 78 78 78 78 78 78 78 78 
----------------------------------------------------------------------

gcc version: gcc (GCC) 7.0.0 20160608 (experimental)

Reply via email to