[LLVMbugs] [Bug 15607] New: Uninitialized register on Shift operation

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 26 22:55:38 PDT 2013


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

            Bug ID: 15607
           Summary: Uninitialized register on Shift operation
           Product: libraries
           Version: 3.1
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: ishiura-compiler at ml.kwansei.ac.jp
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Apple clang 4.1 (based on LLVM 3.1svn) seems to miscompile the
following C program with optimize option -O1.

  $ cat test.c

  int x = 0;
  int main (void)
  {
    return ( 1 >> ( x << 8 ) );  /* should return 1 */
  }

  $ clang -O1 test.c
  $ ./a.out
  $ echo $?
  0

Note that a.out may yield correct output (1) depending on
environments.  This seems to happen because register "%cl" on the
"shrl" instruction is not initialized in the generated code.

     pushq  %rbp
   Ltmp2:
     .cfi_def_cfa_offset 16
   Ltmp3:
     .cfi_offset %rbp, -16
     movq  %rsp, %rbp
   Ltmp4:
     .cfi_def_cfa_register %rbp
     movl  $1, %eax
     shrl  %cl, %eax
     popq  %rbp
     ret

The code may be valid for x != 0 (due to undefined behavior), but not
for x == 0.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130327/1a2c0e0e/attachment.html>


More information about the llvm-bugs mailing list