www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - code generation/optimizer bug

#include <stdio.h>

char *f(char *c)
{
  return c + 1;
}

void g(char *ptr)
{
  char *p;
  char c;

  c = *ptr;
  *ptr = '\0';
  if (f(ptr))
  {
    *ptr = c;
    p = ptr;
    if (c == '(')
    {
      printf("OK\n");
    }

    *p++ = '\0';
    if (*p != '\0')
    {
      f(p);
    }
  }
}

int main()
{
  g("(abc)");

  return 0;
}


This test-case should print "OK", but it doesn't if compiled with -o+speed

Here ist the generated assembler code:

?g  YAXPAD Z:
		push	EAX
		push	EAX
		push	EBX
		mov	EBX,010h[ESP]
		mov	AL,[EBX]                ; c = *ptr
		push	ESI
		mov	0Ch[ESP],AL
		mov	byte ptr [EBX],0        ; *ptr = '\0';
		push	EBX
		call	near ptr ?f  YAPADPAD Z ; f(ptr);
		add	ESP,4
		test	EAX,EAX
		je	L50
		mov	AL,0Ch[ESP]
		mov	ESI,EBX                 ; p = ptr
		mov	[EBX],AL                ; *ptr = c
		cmp	BL,028h  ; But this one should be "cmp AL, 028h"

		jne	L3E
		push	offset FLAT:_DATA
		call	near ptr _printf
		add	ESP,4


BTW, I have tried it with DMC 8.37.7 and 8.38.2.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Oct 26 2003