Skip to content

Commit 135c195

Browse files
authored
Handle in-place construction of temporaries more cleanly (#5015)
Pre-set the lvalue of the temporary instead of IR-replacing the initial alloca with the target address afterwards.
1 parent e6259c3 commit 135c195

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

gen/toir.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,17 +3000,20 @@ bool toInPlaceConstruction(DLValue *lhs, Expression *rhs) {
30003000
return true;
30013001
}
30023002
// and temporaries
3003-
else if (isTemporaryVar(rhs)) {
3003+
else if (auto vd = isTemporaryVar(rhs)) {
30043004
Logger::println("success, in-place-constructing temporary");
3005-
auto lhsLVal = DtoLVal(lhs);
3006-
auto rhsLVal = DtoLVal(rhs);
3007-
if (!llvm::isa<llvm::AllocaInst>(rhsLVal)) {
3008-
error(rhs->loc, "lvalue of temporary is not an alloca, please "
3009-
"file an LDC issue");
3010-
fatal();
3011-
}
3012-
if (lhsLVal != rhsLVal)
3013-
rhsLVal->replaceAllUsesWith(lhsLVal);
3005+
assert(!isSpecialRefVar(vd) && "Can this happen?");
3006+
3007+
// evaluate lhs to an lvalue, the target address
3008+
auto lval = DtoLVal(lhs);
3009+
3010+
// pre-set the lvalue of the temporary to that address
3011+
getIrLocal(vd, true)->value = lval;
3012+
gIR->DBuilder.EmitLocalVariable(lval, vd);
3013+
3014+
// evaluate rhs, constructing the pre-allocated temporary
3015+
toElem(rhs);
3016+
30143017
return true;
30153018
}
30163019

0 commit comments

Comments
 (0)