http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51667

--- Comment #7 from Uros Bizjak <ubizjak at gmail dot com> 2011-12-24 12:20:24 
UTC ---
REE pass miscompiles std::ostream::operator<<(short):

Dump of assembler code for function std::ostream::operator<<(short):
=> 0x001998f0 <+0>:     push   %ebx
   0x001998f1 <+1>:     sub    $0x18,%esp
   0x001998f4 <+4>:     call   0x156e4b <__x86.get_pc_thunk.bx>
   0x001998f9 <+9>:     add    $0x5a6fb,%ebx
   0x001998ff <+15>:    mov    0x20(%esp),%edx
   0x00199903 <+19>:    movzwl 0x24(%esp),%ecx
   0x00199908 <+24>:    mov    %edx,(%esp)
   0x0019990b <+27>:    mov    %ecx,0x4(%esp)
   0x0019990f <+31>:    call   0x154630 <_ZNSo9_M_insertIlEERSoT_@plt>
   0x00199914 <+36>:    add    $0x18,%esp
   0x00199917 <+39>:    pop    %ebx
   0x00199918 <+40>:    ret    
End of assembler dump.

This is without REE pass:

Dump of assembler code for function std::ostream::operator<<(short):
=> 0x00199960 <+0>:     push   %ebx
   0x00199961 <+1>:     sub    $0x18,%esp
   0x00199964 <+4>:     mov    0x20(%esp),%edx
   0x00199968 <+8>:     call   0x156e4b <__x86.get_pc_thunk.bx>
   0x0019996d <+13>:    add    $0x5b687,%ebx
   0x00199973 <+19>:    movzwl 0x24(%esp),%ecx
   0x00199978 <+24>:    mov    (%edx),%eax
   0x0019997a <+26>:    mov    -0xc(%eax),%eax
   0x0019997d <+29>:    mov    0xc(%edx,%eax,1),%eax
   0x00199981 <+33>:    and    $0x4a,%eax
   0x00199984 <+36>:    cmp    $0x8,%eax
   0x00199987 <+39>:    je     0x1999a8 <std::ostream::operator<<(short)+72>
   0x00199989 <+41>:    cmp    $0x40,%eax
   0x0019998c <+44>:    je     0x1999a8 <std::ostream::operator<<(short)+72>
   0x0019998e <+46>:    movswl %cx,%ecx
   0x00199991 <+49>:    mov    %ecx,0x4(%esp)
   0x00199995 <+53>:    mov    %edx,(%esp)
   0x00199998 <+56>:    call   0x154630 <_ZNSo9_M_insertIlEERSoT_@plt>
   0x0019999d <+61>:    add    $0x18,%esp
   0x001999a0 <+64>:    pop    %ebx
   0x001999a1 <+65>:    ret    
   0x001999a2 <+66>:    lea    0x0(%esi),%esi
   0x001999a8 <+72>:    movzwl %cx,%ecx
   0x001999ab <+75>:    mov    %ecx,0x4(%esp)
   0x001999af <+79>:    mov    %edx,(%esp)
   0x001999b2 <+82>:    call   0x154630 <_ZNSo9_M_insertIlEERSoT_@plt>
   0x001999b7 <+87>:    add    $0x18,%esp
   0x001999ba <+90>:    pop    %ebx
   0x001999bb <+91>:    ret    
End of assembler dump.

Just break at _ZNSolsEs to see wrong code in action. Please also note movsl in
good code.

Reply via email to