:>: -----Original Message-----
:>: From: IBM Mainframe Discussion List [mailto:[email protected]] On
:>: Behalf Of Paul Gilmartin
:>: Sent: Thursday, May 08, 2014 3:36 PM
:>: To: [email protected]
:>: Subject: Re: Another C compiler shift bug?
:>:
:>: On Thu, 8 May 2014 15:16:26 -0700, Charles Mills wrote:
:>:
:>: >Am I missing something here? Consider the following C statement:
:>: >
:>: >unsigned long long maxBit = 0x1 << (arraySize-3);
:>: >
:>: >When arraySize is 66, maxBit is ending up as zero (instead of what I
:>: would
:>: >expect, X'8000000000000000'. Am I missing something?
:>: >
:>: >Here is the LIST output. (No optimization.)
:>: >
:>: >*      unsigned long long maxBit = 0x1 << (arraySize-3);
:>: >          EX       r0,HOOK..STMT
:>: >          L        r1,arraySize(,r13,240)
:>: >          AHI      r1,H'-3'
:>: >          LA       r2,1
:>: >          LR       r0,r2
:>: >          SLL      r0,0(r1)
:>: >          LR       r1,r0
:>: >          SRA      r1,31
:>: >          ST       r1,maxBit(,r13,248)
:>: >          ST       r0,maxBit(,r13,252)
:>: >
:>: >Won't SLL R0,0(R1) yield a zero for any shift values greater than 31?
:>: >
:>: Does it work better with a cast:
:>:
:>:     unsigned long long maxBit = (long long) 0x1 << (arraySize-3);?
:>:
:>: I might then expect:
:>:
:>:           SLDL      r0,0(r1)

As written it causes undefined behavior because long long is signed and you
are shifting a different value into the sign bit.  Changing the cast to
(unsigned long long) will work.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to