Using gcc 4.4.0 20090226 with -Os on: int f(int a) { if (!a) { return 0; } else { volatile int vla[a]; vla[0] = 0; return vla[0]; } }
gives: _f: pushl %ebp xorl %eax, %eax movl %esp, %ebp subl $8, %esp movl 8(%ebp), %edx testl %edx, %edx je L3 movl %esp, %ecx leal 30(,%edx,4), %eax andl $-16, %eax subl %eax, %esp leal 15(%esp), %eax andl $-16, %eax movl $0, (%eax) movl (%eax), %eax movl %ecx, %esp L3: leave ret Adding -fomit-frame-pointer gives the exact same result. ebp shouldn't be saved here, since esp is saved to and restored from ecx anyway, so it's not actually used for anything. This isn't just a problem for crazy asm - gcc errors if an asm clobbers ebp in a function with VLAs- but also means that inlining a function with VLAs makes generated code worse, since the entire function loses one register. -- Summary: x86 use of VLA disables -fomit-frame-pointer Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: astrange at ithinksw dot com GCC build triplet: i?86-*-* GCC host triplet: i?86-*-* GCC target triplet: i?86-*-* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39337