http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49519
--- Comment #4 from Yukhin Kirill <kirill.yukhin at intel dot com> 2011-06-29
05:06:04 UTC ---
I've dived into the problem yesterday.
Seems the problem is connected with tail call optimization.
The refined difference is below. Assembler is extracted from step-14.cc
Tail call optimization converts this code:
.cfi_startproc
pushl %ebx
.cfi_def_cfa_offset 8
.cfi_offset 3, -8
subl $40, %esp
.cfi_def_cfa_offset 48
movl 52(%esp), %eax
movl 56(%esp), %ecx
movl 60(%esp), %ebx
movl %eax, %edx
testb $1, %al
je .L1498
movl (%ebx,%ecx), %edx
movl -1(%edx,%eax), %edx
.L1498:
movl 76(%esp), %eax
movl %eax, 16(%esp)
movl 72(%esp), %eax
movl %eax, 12(%esp)
movl 68(%esp), %eax
movl %eax, 8(%esp)
movl 64(%esp), %eax
movl %eax, 4(%esp)
addl %ebx, %ecx
movl %ecx, (%esp)
call *%edx
addl $40, %esp
.cfi_def_cfa_offset 8
popl %ebx
.cfi_def_cfa_offset 4
.cfi_restore 3
ret
To the following tail call optimized
.cfi_startproc
subl $8, %esp
.cfi_def_cfa_offset 12
movl %ebx, (%esp)
movl %esi, 4(%esp)
movl 16(%esp), %eax
movl 20(%esp), %ecx
movl 24(%esp), %ebx
.cfi_offset 6, -8
.cfi_offset 3, -12
movl %eax, %edx
testb $1, %al
je .L1498
movl (%ebx,%ecx), %edx
movl -1(%edx,%eax), %edx
.L1498:
movl 40(%esp), %eax
movl %eax, 28(%esp)
movl 36(%esp), %esi
movl %esi, 24(%esp)
movl 32(%esp), %esi
movl %esi, 20(%esp)
movl %eax, 16(%esp)
addl %ebx, %ecx
movl %ecx, 12(%esp)
movl (%esp), %ebx
movl 4(%esp), %esi
addl $8, %esp
.cfi_def_cfa_offset 4
.cfi_restore 6
.cfi_restore 3
jmp *%edx
I've prepared to assemblers of step-14 with the only difference mentioned
above.
dealII compiled with first snippet works just fine, while tail-optimized case
gives SegFault
I believe the problem is that stack adjustment is wrong here.
Continuing looking into