Bug 6096 – optimizer assert on cdouble to bool conversion
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-03T00:52:00Z
Last change time
2015-06-09T05:14:56Z
Keywords
ice, patch, wrong-code
Assigned to
nobody
Creator
r.sagitario
Comments
Comment #0 by r.sagitario — 2011-06-03T00:52:36Z
this code:
cdouble c;
int main()
{
if (c) return 0;
return 1;
}
compiles with dmd 2.053 unless optimizations are turned on:
c:\tmp>c:\l\dmd-2.053\windows\bin\dmd -O ccmp.d
Internal error: ..\ztc\el.c 904
Comment #1 by r.sagitario — 2011-06-03T01:27:21Z
It seems, an optimization is tried with the comment "Try to replace (e1) with (e1 >= 1)", but does not work well with floating point numbers. It seems strange for integer values aswell.
Here's a possible patch
diff --git a/src/backend/cgelem.c b/src/backend/cgelem.c
index 5cc6d48..be7a944 100644
--- a/src/backend/cgelem.c
+++ b/src/backend/cgelem.c
@@ -1752,7 +1752,7 @@ STATIC elem * elcond(elem *e)
}
}
}
- else
+ else if(tyintegral(e1->Ety))
e->E1 = el_bin(OPge,TYint,e1,el_long(touns(e1->Ety),1));
}
#endif
Considering the patch, I realized that
double c = 0.5;
void main()
{
assert((c ? 0 : 1) == 0);
}
runs fine when compiled without -O, but asserts with -O.