[Issue 2756] New: Bad code generation for pure nothrow math functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 24 01:04:13 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2756
Summary: Bad code generation for pure nothrow math functions
Product: D
Version: 2.025
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: clugdbug at yahoo.com.au
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 !!
}
--
More information about the Digitalmars-d-bugs
mailing list