The attached C source gives wrong output when compiled with inlined functions (-O3 or -O2 -finline-functions) with gcc-4.1-20050501 or gcc-4.0.0. Compiling gives the following warning twice: dereferencing type-punned pointer will break strict-aliasing rules
The expected output is 0 0, the actual output is two large values. Without inlined functions or with the unsigned char pointers changed to char pointers the problem disappears. There seem to be two problems. One seems to be using an uninitialised stack value for the pointer which should be initialized to the empty string. The other seems to be that a pointer (the p2 pointer in the findlast function in the first inlined readlen call) is modified in a register and is not written back to the stack before it is read from the stack (to calculate the return value). On (RedHat modified) gcc 3.4 the output is 0 -1 (it has only the second problem) and in the actual application there was no problem with gcc 3.3 and before. -- Summary: wrong-code with inlining and type-punned pointer Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gcc at arbruijn dot dds dot nl CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21402