Subject: Re: (mips): egcs on -current miscompiles strtod.c
To: Jonathan Stone <jonathan@DSG.Stanford.EDU>
From: Simon Burge <>
List: tech-toolchain
Date: 02/06/1999 00:43:35
On Thu, 04 Feb 1999 19:29:23 -0800  Jonathan Stone wrote:

> hi all,
> There seems to be a bug in an EGCS-compiled strtod.c.
> This breaks Perl ("10" gets printed as ":", etc) an a few other
> things. (someone mentioned top recently on port-pmax).

Here's a quick'n'dirty bit of code based on part of the perl
configuration test program:

	#define RES     "0.1"
		char buf[16];

		sprintf(buf, "%.*g", 8, 0.1);
		printf("\"%s\" vs. \"%s\": %s\n", buf, RES,
		    strcmp(buf, RES) == 0 ? "pass" : "fail");

On pre-1.3.4:
	vlad:~ 23> cc -o foo foo.c
	vlad:~ 24> ./foo
	"0.1" vs. "0.1": pass
On -current (3 weeks old):
	mona:~ 23> cc -o foo foo.c
	mona:~ 24> ./foo
	"0.0:" vs. "0.1": fail
On -current (3 weeks old) with 1.3.4ish strtod.o:
	mona:~ 23> cc -o foo foo.c strtod.o
	mona:~ 24> ./foo
	"0.1" vs. "0.1": pass

I hadn't noticed the problem until now.  I just tried a clean perl build
(the original thing, not pkgsrc) and got a "sprinf oddity" error...

AHA!  Looking more, it looks like an optimisation error:

	mona:~ 77> cc -I/NetBSD/src/lib/libc/{include,stdio} -c -O1 strtod.c
	mona:~ 78> cc -o foo foo.o strtod.o
	mona:~ 79> ./foo
	"0.1" vs. "0.1": pass
	mona:~ 80> cc -I/NetBSD/src/lib/libc/{include,stdio} -c -O2 strtod.c
	mona:~ 81> cc -o foo foo.o strtod.o
	mona:~ 82> ./foo
	"0.0:" vs. "0.1": fail

I guess the simple fix is to back out -O2 for mips in  I'll
do that now.