This is basically a copy of bug report from http://www.dribin.org/dave/blog/archives/2006/12/05/missing_third_param/
Using the following sample file saved as test.c: ---------------------------------------------------------------------------- #include <stdio.h> #define NOINLINE __attribute__((noinline)) NOINLINE static void foo1(int i1) { printf("foo1: %d\n", i1); } NOINLINE static void foo2(int i1, int i2) { printf("foo2: %d, %d\n", i1, i2); } NOINLINE static void foo3(int i1, int i2, int i3) { printf("foo3: %d, %d, %d\n", i1, i2, i3); } NOINLINE static void foo4(int i1, int i2, int i3, int i4) { printf("foo4: %d, %d, %d, %d\n", i1, i2, i3, i4); } NOINLINE static void foo5(int i1, int i2, int i3, int i4, int i5) { printf("foo5: %d, %d, %d, %d, %d\n", i1, i2, i3, i4, i5); } NOINLINE static void foo6(int i1, int i2, int i3, int i4, int i5, int i6) { printf("foo6: %d, %d, %d, %d, %d, %d\n", i1, i2, i3, i4, i5, i6); } int main(int argc, char **argv) { foo1(1); foo2(1, 2); foo3(1, 2, 3); foo4(1, 2, 3, 4); foo5(1, 2, 3, 4, 5); foo6(1, 2, 3, 4, 5, 6); return 0; } ---------------------------------------------------------------------------- produces invalid output (broken 3rd parameter) if compiled using g++ and -mstackrealign: > /usr/toolchains/gcc433/bin/g++ -Wall -mstackrealign -O2 test.c > ./a.out foo1: 1 foo2: 1, 2 foo3: 1, 2, -1209632279 foo4: 1, 2, 4, 134520820 foo5: 1, 2, 4, 5, -1074446840 foo6: 1, 2, 4, 5, 6, 134514537 However if gcc is used instead of g++, valid output is generated: > /usr/toolchains/gcc433/bin/gcc -mstackrealign -Wall -O2 test.c > ./a.out foo1: 1 foo2: 1, 2 foo3: 1, 2, 3 foo4: 1, 2, 3, 4 foo5: 1, 2, 3, 4, 5 foo6: 1, 2, 3, 4, 5, 6 Analyze of assembly dump revealed that GCC still uses ECX in main() to pass the parameter. ix86_internal_arg_pointer() in i386.c works fine, and returns same values for gcc and g++, so the problem is not there. -- Summary: -mstackalign breaks -O2 optimization using g++ Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gyunaev at ulduzsoft dot com 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=39163