[LLVMbugs] [Bug 19500] New: Right-shift operator returns incorrect and inconsistent values

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 21 09:36:56 PDT 2014


            Bug ID: 19500
           Summary: Right-shift operator returns incorrect and
                    inconsistent values
           Product: clang
           Version: 3.4
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chris.cooper at veranmedical.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12416
  --> http://llvm.org/bugs/attachment.cgi?id=12416&action=edit
Short source code showing the problem

Compiling the attached test program with no flags (just "clang++ shift.cpp")
shows several problems with the right-shift operator.

Right-shifting by a large value should always return zero (according to my
reading of the C++ ISO spec, section 5.8.3).

1) Executing the program "as is" gives this output:

Main: 48271 >> 1291394886 = 754; rx=0=0x0=long:0; (lx>>ix)=long:754
Test: 48271 >> 1291394886; (lx>>ix)=754; rx=754=0x2f2=long:754;
lx (8 bits) = 48271 =  = bc8f
ix (4 bits) = 1291394886 =  = 4cf91f46

1a) In the main() function, storing the result of the shift in a variable (rx)
results in the correct zero value, but passing the result of the shift either
to std::cout or to a simple print_value() function gives a non-zero result

1b) When the exact same values are passed to a function for evaluation, the
right-shift operator returns the same invalid value whether the result is
stored first or not.

Perhaps more disturbing:

Commenting out the last two lines of the main() function results in a
drastically wrong value being stored and reported:

Main: 48271 >> 1291394886 = 754;
rx=140734645460120=0x7fff568cdc98=long:140734645460120; (lx>>ix)=long:754

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/20140421/3e768d41/attachment.html>

More information about the llvm-bugs mailing list