Skip to content

Commit

Permalink
Lower CmpExp between classes to __cmp call
Browse files Browse the repository at this point in the history
  • Loading branch information
edi33416 committed Dec 17, 2021
1 parent 1c66d43 commit 281b49e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -11333,6 +11333,24 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
}

if (t1.ty == Tclass && t2.ty == Tclass)
{
// Lower to object.__cmp(e1, e2)
Expression cl = new IdentifierExp(exp.loc, Id.empty);
cl = new DotIdExp(exp.loc, cl, Id.object);
cl = new DotIdExp(exp.loc, cl, Id.__cmp);
cl = cl.expressionSemantic(sc);

auto arguments = new Expressions();
arguments.push(exp.e1);
arguments.push(exp.e2);

cl = new CallExp(exp.loc, cl, arguments);
cl = new CmpExp(exp.op, exp.loc, cl, new IntegerExp(0));
result = cl.expressionSemantic(sc);
return;
}

EXP cmpop;
if (auto e = exp.op_overload(sc, &cmpop))
{
Expand Down

0 comments on commit 281b49e

Please sign in to comment.