Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8178348

left_n_bits(0) invokes undefined behavior

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      The current definition of left_n_bits is

      #define left_n_bits(n) \
        (right_n_bits(n) << (((n) >= BitsPerWord) ? 0 : (BitsPerWord - (n))))

      When n == 0, this reduces to

        (right_n_bits(0) << BitsPerWord)

      According to C++03 5.8/2, the behavior of a shift expression is undefined if the right operand is greater than or equal to the length in bits of the promoted left operand. So a shift by BitsPerWord invokes undefined behavior.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                kbarrett Kim Barrett
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: