diff --git a/gen/toir.cpp b/gen/toir.cpp index fcc7054c648..a69d5153696 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2095,7 +2095,7 @@ class ToElemVisitor : public Visitor { p->ir->SetInsertPoint(condtrue); PGO.emitCounterIncrement(e); - DValue *u = toElem(e->e1); + DValue *u = toElemDtor(e->e1); if (retPtr && u->type->toBasetype()->ty != TY::Tnoreturn) { LLValue *lval = makeLValue(e->loc, u); DtoStore(lval, DtoBitCast(retPtr, lval->getType()->getPointerTo())); @@ -2103,7 +2103,7 @@ class ToElemVisitor : public Visitor { llvm::BranchInst::Create(condend, p->scopebb()); p->ir->SetInsertPoint(condfalse); - DValue *v = toElem(e->e2); + DValue *v = toElemDtor(e->e2); if (retPtr && v->type->toBasetype()->ty != TY::Tnoreturn) { LLValue *lval = makeLValue(e->loc, v); DtoStore(lval, DtoBitCast(retPtr, lval->getType()->getPointerTo())); diff --git a/tests/codegen/gh4570.d b/tests/codegen/gh4570.d new file mode 100644 index 00000000000..2a25b57f5ef --- /dev/null +++ b/tests/codegen/gh4570.d @@ -0,0 +1,11 @@ +// RUN: %ldc -c %s + +struct S { + ~this() {} +} + +int foo(S[] ss...) { return 0; } + +void bar(bool a) { + const r = a ? foo(S()) : foo(S()); +}