https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66086
Bug ID: 66086 Summary: Casting a pointer to a double confuses the optimizer Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: agriff at tin dot it Target Milestone: --- Created attachment 35510 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35510&action=edit Small program showing the problem When compiling double doit() { double *ptr = (double *)malloc(sizeof(double)); ptr[0] = 3.14; return (double)((uintptr_t) ptr); } the generated code doesn't initialize the memory returned by `malloc` when the optimization level is -O2. This happens both in 64-bit mode and in 32-bit mode (where the size of uintptr_t is 4 bytes and all theoretic values can be represented exactly in a double); note that on x86-64 the used values are 48-bit only and a double provides enough accuracy to store them correctly. Attached is a full program showing the issue (compiled with -O0 the result is correct, compiled with -O2 the result is wrong).