[LLVMbugs] [Bug 3709] New: Clang miscompiles crtend.

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Mar 3 08:02:14 PST 2009


http://llvm.org/bugs/show_bug.cgi?id=3709

           Summary: Clang miscompiles crtend.
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ed at 80386.nl
                CC: llvmbugs at cs.uiuc.edu
            Blocks: 3696


Created an attachment (id=2649)
 --> (http://llvm.org/bugs/attachment.cgi?id=2649)
Reduced testcase

When compiling the attached code without any optimization on x86_64, Clang
generates the following:

0000000000000000 <__do_global_ctors_aux>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 83 ec 10             sub    $0x10,%rsp
   8:   48 8d 04 25 00 00 00    lea    0x0,%rax
   f:   00 
  10:   48 b9 f8 ff ff ff ff    mov    $0xfffffffffffffff8,%rcx
  17:   ff ff ff 
  1a:   48 01 c8                add    %rcx,%rax
  1d:   48 89 45 f8             mov    %rax,0xfffffffffffffff8(%rbp)
  21:   48 8b 45 f8             mov    0xfffffffffffffff8(%rbp),%rax
  25:   48 8b 00                mov    (%rax),%rax
  28:   b9 ff ff ff ff          mov    $0xffffffff,%ecx
  2d:   89 c9                   mov    %ecx,%ecx
  2f:   48 39 c8                cmp    %rcx,%rax
  32:   74 20                   je     54 <__do_global_ctors_aux+0x54>
  34:   48 8b 45 f8             mov    0xfffffffffffffff8(%rbp),%rax
  38:   48 8b 00                mov    (%rax),%rax
  3b:   ff d0                   callq  *%eax
  3d:   48 8b 45 f8             mov    0xfffffffffffffff8(%rbp),%rax
  41:   48 b9 f8 ff ff ff ff    mov    $0xfffffffffffffff8,%rcx
  48:   ff ff ff 
  4b:   48 01 c8                add    %rcx,%rax
  4e:   48 89 45 f8             mov    %rax,0xfffffffffffffff8(%rbp)
  52:   eb cd                   jmp    21 <__do_global_ctors_aux+0x21>
  54:   48 83 c4 10             add    $0x10,%rsp
  58:   5d                      pop    %rbp
  59:   c3                      retq   

If we turn on the optimizer, we get:

0000000000000000 <__do_global_ctors_aux>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   30 c0                   xor    %al,%al
   6:   66                      data16
   7:   66                      data16
   8:   66                      data16
   9:   90                      nop    
   a:   66                      data16
   b:   66                      data16
   c:   90                      nop    
   d:   66                      data16
   e:   66                      data16
   f:   90                      nop    
  10:   f6 d0                   not    %al
  12:   a8 01                   test   $0x1,%al
  14:   b0 00                   mov    $0x0,%al
  16:   75 f8                   jne    10 <__do_global_ctors_aux+0x10>
  18:   5d                      pop    %rbp
  19:   c3                      retq   

GCC generates the following code when using -O:

0000000000000000 <__do_global_ctors_aux>:
   0:   53                      push   %rbx
   1:   48 8b 05 00 00 00 00    mov    0(%rip),%rax        # 8
<__do_global_ctors_aux+0x8>
   8:   48 83 f8 ff             cmp    $0xffffffffffffffff,%rax
   c:   74 18                   je     26 <__do_global_ctors_aux+0x26>
   e:   bb 00 00 00 00          mov    $0x0,%ebx
  13:   ff d0                   callq  *%eax
  15:   48 8b 83 00 00 00 00    mov    0x0(%rbx),%rax
  1c:   48 83 eb 08             sub    $0x8,%rbx
  20:   48 83 f8 ff             cmp    $0xffffffffffffffff,%rax
  24:   75 ed                   jne    13 <__do_global_ctors_aux+0x13>
  26:   5b                      pop    %rbx
  27:   c3                      retq


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list