www.digitalmars.com         C & C++   DMDScript  

c++ - Optimiser bug ?

Here is a small program compiled with:
Digital Mars C/C++ Compiler Version 8.52.5n

I think there is a bug introduced by the optimiser.

Am I right ?


extern unsigned long D2UL(double);

unsigned long d2ul()
{
  union
  { double d;
    struct { unsigned long a,b; } S;
  } U;
  U.S.a = _EDX;
  U.S.b = _EAX;
  return D2UL(U.d);
}

#pragma alias("__DBLULNG ","_d2ul")

void main()
{
  double d;
  unsigned long ul;
  d=(double)-1;
  ul=d;
}

/*
 * compiled with: dmc -o -c -cod u5   (optimised)
 */

_d2ul:
    sub ESP,01Ch
    mov 4[ESP],EDX
    mov 8[ESP],EAX
    //  pushing the same piece 2 times ?
    push  dword ptr 8[ESP]
    push  dword ptr 8[ESP]
    call  near ptr _D2UL
    add ESP,024h
    ret

/*
 * compiled with: dmc -c -cod u5      (no optimisation)
 */

_d2ul:
    enter 8,0
    mov -8[EBP],EDX
    mov -4[EBP],EAX
    //  pushing 2 pieces
    push  dword ptr -4[EBP]
    push  dword ptr -8[EBP]
    call  near ptr _D2UL
    add ESP,8
    leave
    ret



begin 666 u5.c
M#0IE>'1E<FX =6YS:6=N960 ;&]N9R!$,E5,*&1O=6)L92D[#0IU;G-I9VYE
M9"!L;VYG(&0R=6PH*0T*>PT*"75N:6]N#0H)>PED;W5B;&4 9#L-" D)<W1R
M=6-T('L =6YS:6=N960 ;&]N9R!A+&([('T 4SL-" E]"54[#0H)52Y3+F$ 
M/2!?1418.PT*"54N4RYB(#T 7T5!6#L-" ER971U<FX 1#)53"A5+F0I.PT*
M?0T*#0HC<')A9VUA(&%L:6%S*")?7T1"3%5,3D= (BPB7V0R=6PB*0T*#0IV
M;VED(&UA:6XH*0T*>PT*"61O=6)L92!D.PT*"75N<VEG;F5D(&QO;F< =6P[
?#0H)9#TH9&]U8FQE*2TQ.PT*"75L/60[#0I]#0H-" ``
`
end
Dec 19 2010