Bug 2756 – Bad code generation for pure nothrow math functions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-03-24T03:04:00Z
Last change time
2015-06-09T01:21:08Z
Keywords
patch, wrong-code
Assigned to
bugzilla
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2009-03-24T03:04:16Z
Bad code generation occurs when the module is called 'std.math' in a module statement, and the signature is exactly 'pure nothrow double XXX(double)' or 'pure nothrow float XXX(float)', and the parameter is a compile-time constant. I suspect this is related to the special treatment of std.math.sqrt(), allowing it to be evaluated at compile time. ---------------- MINIMAL TEST CASE: ---------------- module std.math; pure nothrow double food(double x){ return 2.0;} void main() { assert( food(1.0) == 2.0 ); } ---------------- FURTHER INFO: ---------------- module std.math; import std.stdio; pure nothrow float foof(float x){return 2.0;} pure nothrow double food(double x){ return 2.0;} pure nothrow real foor(real x) { return 2.0; } void main() { writefln(foor(1.0)); // writes 2. OK. writefln(food(1.0)); // writes -0 !! writefln(foof(1.0)); // writes 0 !! }
Comment #1 by clugdbug — 2009-03-24T05:36:06Z
Patch: builtin.c line 62 -------- if (ident == Id::_sqrt) // add this line builtin = BUILTINsqrt; --------
Comment #2 by bugzilla — 2009-03-27T03:36:33Z
Eh, that's an embarassing one!
Comment #3 by bugzilla — 2009-04-01T13:57:41Z
Fixed DMD 2.027