Skip to content

Commit

Permalink
Fix Issue 3918 - Parameter use before its use in an AndAnd expression…
Browse files Browse the repository at this point in the history
… with reals treats NaN as false
  • Loading branch information
yebblies committed Jul 25, 2014
1 parent 031c94f commit d089a3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/backend/cod3.c
Expand Up @@ -1862,19 +1862,23 @@ int jmpopcode(elem *e)
e = e->E2; /* right operand determines it */

op = e->Eoper;
tym_t tymx = tybasic(e->Ety);
bool needsNanCheck = tyfloating(tymx) && config.inline8087 &&
(tymx == TYldouble || tymx == TYildouble || tymx == TYcldouble ||
tymx == TYcdouble || tymx == TYcfloat ||
op == OPind ||
(OTcall(op) && (regmask(tymx, tybasic(e->E1->Eoper)) & (mST0 | XMMREGS))));
if (e->Ecount != e->Ecomsub) // comsubs just get Z bit set
return JNE;
{
if (needsNanCheck) // except for floating point values that need a NaN check
return XP|JNE;
else
return JNE;
}
if (!OTrel(op)) // not relational operator
{
tym_t tymx = tybasic(e->Ety);
if (tyfloating(tymx) && config.inline8087 &&
(tymx == TYldouble || tymx == TYildouble || tymx == TYcldouble ||
tymx == TYcdouble || tymx == TYcfloat ||
op == OPind ||
(OTcall(op) && (regmask(tymx, tybasic(e->E1->Eoper)) & (mST0 | XMMREGS)))))
{
if (needsNanCheck)
return XP|JNE;
}
return ((op >= OPbt && op <= OPbts) || op == OPbtst) ? JC : JNE;
}

Expand Down
22 changes: 22 additions & 0 deletions test/runnable/mars1.d
Expand Up @@ -436,6 +436,27 @@ void test12095(int k)
////////////////////////////////////////////////////////////////////////


bool test3918a( float t, real u )
{
printf("%f\n", u );
return t && u;
}

bool test3918b( real t, float u )
{
printf("%f\n", t );
return t && u;
}

void test3918()
{
assert(test3918a(float.nan, real.nan));
assert(test3918b(real.nan, float.nan));
}

////////////////////////////////////////////////////////////////////////


int div10(int x)
{
return x / 10;
Expand Down Expand Up @@ -1221,6 +1242,7 @@ int main()
test8658();
testfastudiv();
testfastdiv();
test3918();
test12051();
testdocond();
testnegcom();
Expand Down

0 comments on commit d089a3a

Please sign in to comment.