https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61300
Bug ID: 61300 Summary: powerpc64le miscompile with K&R-style function definition at -O0 Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: brooks at gcc dot gnu.org We've run into a GCC miscompile problem with K&R-style function definitions that's causing some various old GNU software to fail in some cases. A simple test case: $ cat bb.c struct builtin { char *name; }; int compare_kr (sbp1, sbp2) struct builtin *sbp1, *sbp2; { return sbp1->name[0] - sbp2->name[0]; } int compare_ansi (struct builtin *sbp1, struct builtin *sbp2) { return sbp1->name[0] - sbp2->name[0]; } On either our Google branch of GCC 4.9 or the Ubuntu system GCC 4.8 on our test machine, we get something like this (annotated to show the difference): $ powerpc64le-unknown-linux-gnu-gcc -S -o- bb.c .file "bb.c" .abiversion 2 .section ".toc","aw" .section ".text" .align 2 .globl compare_kr .type compare_kr, @function compare_kr: std 31,-8(1) stdu 1,-48(1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it allocates 48 bytes for the frame mr 31,1 std 3,80(31) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and then writes way past this std 4,88(31) ld 9,80(31) ... .globl compare_ansi .type compare_ansi, @function compare_ansi: std 31,-8(1) stdu 1,-64(1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ allocates 64 bytes mr 31,1 std 3,40(31) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and saves within the confines of the frame std 4,32(31) ld 9,40(31) ... In this testcase, this seems to go away if we turn on -O2. I'm not sure if that's always the case or not. I've also confirmed that this does _not_ happen with the x86_64 compiler built from the same source branch.