Skip to content

Commit

Permalink
Work around Valgrind choking on redundant REX.W prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Sep 22, 2015
1 parent 5d40a78 commit 4bc2030
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,21 @@ extern (C++) UnionExp Div(Type type, Expression e1, Expression e2)
{
if (e1.type.isreal())
{
emplaceExp!(RealExp)(&ue, loc, e1.toReal() / e2.toReal(), type);
version (all)
{
// Work around redundant REX.W prefix breaking Valgrind
// when built with affected versions of DMD.
// https://issues.dlang.org/show_bug.cgi?id=14952
// This can be removed once compiling with DMD 2.068 or
// older is no longer supported.
d_float80 r1 = e1.toReal();
d_float80 r2 = e2.toReal();
emplaceExp!(RealExp)(&ue, loc, r1 / r2, type);
}
else
{
emplaceExp!(RealExp)(&ue, loc, e1.toReal() / e2.toReal(), type);
}
return ue;
}
r = e2.toReal();
Expand Down
21 changes: 19 additions & 2 deletions src/optimize.d
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,25 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
return;
}
// If e2 *could* have been an integer, make it one.
if (e.e2.op == TOKfloat64 && (e.e2.toReal() == cast(sinteger_t)e.e2.toReal()))
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
if (e.e2.op == TOKfloat64)
{
version (all)
{
// Work around redundant REX.W prefix breaking Valgrind
// when built with affected versions of DMD.
// https://issues.dlang.org/show_bug.cgi?id=14952
// This can be removed once compiling with DMD 2.068 or
// older is no longer supported.
d_float80 r = e.e2.toReal();
if (r == cast(sinteger_t)r)
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
}
else
{
if (e.e2.toReal() == cast(sinteger_t)e.e2.toReal())
e.e2 = new IntegerExp(e.loc, e.e2.toInteger(), Type.tint64);
}
}
if (e.e1.isConst() == 1 && e.e2.isConst() == 1)
{
Expression ex = Pow(e.type, e.e1, e.e2).copy();
Expand Down

0 comments on commit 4bc2030

Please sign in to comment.