Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!UUNET.UU.NET!mcvax!ruuinf!piet From: mcvax!ruuinf!piet@UUNET.UU.NET (Piet van Oostrum) Newsgroups: gnu.g++.bug Subject: Bug in g++ 1.32.0 for new. Message-ID: <8902101647.AA18799@cs.ruu.nl> Date: 10 Feb 89 16:47:07 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 83 g++ generates incorrect code for new type [i] if type is a class. The code tests for i being zero, but fails to put a NULL pointer in the register where the result is delivered. I don't know if i==0 is correct C++, but the test5[ab] programs from the library (libg++-1.25.0/tests) actually use this (e.g. to initialize nil_Integer_rep). The example is on a Sun3 OS3. ------------------------------------------------------------------------ The program: #include extern myfunc(Integer *i); main() { int i; Integer *a = new Integer [i]; myfunc (a); } ------------------------------------------------------------------------ g++ -v -S temp1.cc g++ version 1.32.0 /usr/staff/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -Dmc68000 -Dsun -Dunix temp1.cc /tmp/cca05970.cpp GNU CPP version 1.32 /usr/staff/lib/gcc-c++ /tmp/cca05970.cpp -quiet -dumpbase temp1.cc -noreg -version -o temp1.s GNU C++ version 1.32.0 (68k, MIT syntax) compiled by CC. ------------------------------------------------------------------------ the code: (some initial stuff deleted) _main: link a6,#-8 moveml #0x3c20,sp@- movel a6@(-4),d3 subql #1,d3 tstl d3 test jlt L1074 branch if (i==0) movel a6@(-4),d0 asll #2,d0 movel d0,sp@- jbsr ___builtin_new movel d0,d2 movel d2,d4 addqw #4,sp L1075: movel d4,a2 movel a6,d0 subql #4,d0 tstl a2 jne L1079 pea 4:w jbsr ___builtin_new movel d0,a2 addqw #4,sp L1079: movel #__nil_Irep,a2@ movel a2,d0 movel d0,d1 jra L1078 L1078: addql #4,d4 L1077: subql #1,d3 moveq #-1,d5 cmpl d3,d5 jeq L1076 jra L1075 L1076: L1074: movel d2,a6@(-8) <== d2 is not set if i==0 movel a6@(-8),sp@- jbsr _myfunc addqw #4,sp L1073: moveml a6@(-28),#0x43c unlk a6 rts Piet van Oostrum, Dept of Computer Science, University of Utrecht Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)