Skip to content

Commit e0f2221

Browse files
authored
fix dlang#21479: Correctly handle casts inlining (dlang#21483)
1 parent fd80c85 commit e0f2221

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

compiler/src/dmd/e2ir.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,7 +3852,8 @@ elem* toElem(Expression e, ref IRState irs)
38523852
printf("\tfrom: %s\n", ce.e1.type.toChars());
38533853
printf("\tto : %s\n", ce.to.toChars());
38543854
}
3855-
elem* e = toElem(ce.e1, irs);
3855+
// When there is a lowering availabe, use that
3856+
elem* e = ce.lowering is null ? toElem(ce.e1, irs) : toElem(ce.lowering, irs);
38563857

38573858
return toElemCast(ce, e, false, irs);
38583859
}
@@ -4788,7 +4789,6 @@ elem* toElemCast(CastExp ce, elem* e, bool isLvalue, ref IRState irs)
47884789
else
47894790
{
47904791
assert(ce.lowering, "This case should have been rewritten to `_d_cast` in the semantic phase");
4791-
e = toElem(ce.lowering, irs);
47924792
}
47934793
}
47944794
return Lret(ce, e);

compiler/src/dmd/inline.d

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -752,21 +752,22 @@ public:
752752
{
753753
auto ue = cast(UnaExp)e.copy();
754754
ue.e1 = doInlineAs!Expression(e.e1, ids);
755-
if (auto ce = ue.isCastExp())
756-
{
757-
if (ce.lowering is null)
758-
goto LskipCastLowering;
755+
result = ue;
756+
}
759757

760-
if (auto lowering = ce.lowering.isCallExp())
761-
{
762-
if (lowering.f.ident == Id._d_cast)
763-
{
764-
ce.lowering = doInlineAs!Expression(lowering, ids);
765-
}
766-
}
758+
override void visit(CastExp e)
759+
{
760+
auto ce = cast(CastExp)e.copy();
761+
if (auto lowering = ce.lowering)
762+
{
763+
ce.lowering = doInlineAs!Expression(lowering, ids);
767764
}
768-
LskipCastLowering:
769-
result = ue;
765+
else
766+
{
767+
ce.e1 = doInlineAs!Expression(e.e1, ids);
768+
}
769+
770+
result = ce;
770771
}
771772

772773
override void visit(AssertExp e)
@@ -1291,6 +1292,18 @@ public:
12911292
inlineScan(e.e1);
12921293
}
12931294

1295+
override void visit(CastExp e)
1296+
{
1297+
if (auto lowering = e.lowering)
1298+
{
1299+
inlineScan(lowering);
1300+
}
1301+
else
1302+
{
1303+
inlineScan(e.e1);
1304+
}
1305+
}
1306+
12941307
override void visit(AssertExp e)
12951308
{
12961309
inlineScan(e.e1);

0 commit comments

Comments
 (0)