[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#135727: buffer overflow (?) in writeln



> When I print floating-point numbers, I sometimes get garbage like this:
> -:.00000000000000/+)))./(/0,,.0.-.0/,.-(e-15

Thanks for the report. However, I'm not quite sure of the GPC
version you have (`gpc -v')  -- Debian's numbering scheme is a
little peculiar ;-). I guess the following means 20011006:

> Package: gpc-2.95
> Source: gcc-2.95 (2.95.4.ds6-0.011006)
> Version: 1:2.95.4-0.011006

I've fixed some bugs WRT writing of real numbers that appeared on
Alpha processors, and it's quite possible that one of those bugs was
also responsible for what you see.

So I'm afraid I can only tell you to wait for the next version (RSN
;-) and test it again.

> writeln('''', -0.0001e-10:w, '''');
> writeln('''', -0.0001e-10:w:p, '''');
> writeln('''', 0.0001e-10:w, '''');
> writeln('''', 0.0001e-10:w:p, '''');
> 
> Feel free to include any of this code (above and/or below) in the
> gpc test suite. You can have it under the 2-clause BSD license.

Thanks. I'll do so, so I'll notice if the problem appears on any
other platform.

> BTW, the assembly output for this code appears to be terribly
> inefficient. (only a minute of study though) Floating-point constants
> seem to get loaded multiple times instead of being kept in registers.

Well, that's really a backend issue, i.e. the GCC developers would
have to deal with it. (If you can reproduce the same behaviour with
C code, it might be worth sending it to them ...)

> For your wishlist, have -Os turn the code below into a loop over
> an array.

Well, I could put it on the list, but I don't really think it will
ever be implemented. After all, it takes quite a bit of effort to
recognize that the statements are "similar" and can be combined. (I
mean effort both for the compiler writers who are always short of
time, and for the compiler, i.e. it would slow down compilations
which probably many people would not appreciate too much.) It raises
the question how similar the code must be -- if, say, every 5th
statement is different, should the compiler automatically create an
`if'?

All in all I don't think the effort is worth the advantage. It seems
much easier for the Pascal programmer to write an array if that's
what he wants. OTOH, it's easier for the compiler to unroll a loop
when optimizing for speed (though actually in this case, it wouldn't
be worth it, since the `WriteLn' call overhead is much bigger than
the loop iteration).

Frank

-- 
Frank Heckenbach, frank@g-n-u.de
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)



Reply to: