D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6096 - optimizer assert on cdouble to bool conversion
Summary: optimizer assert on cdouble to bool conversion
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice, patch, wrong-code
Depends on:
Blocks:
 
Reported: 2011-06-03 00:52 UTC by Rainer Schuetze
Modified: 2015-06-09 05:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2011-06-03 00:52:36 UTC
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 Rainer Schuetze 2011-06-03 01:27:21 UTC
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
Comment 2 Rainer Schuetze 2011-10-15 02:12:04 UTC
https://github.com/D-Programming-Language/dmd/pull/452
Comment 3 Rainer Schuetze 2011-10-23 23:35:04 UTC
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.
Comment 4 yebblies 2012-02-23 00:48:19 UTC
The patch was merged 3 months ago.

https://github.com/D-Programming-Language/dmd/commit/58507a208e12d0b7e44111f5eabd6747e5d79925