From f3cb8dc79a91dd7de94f3901a8ec50f7184a1c44 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Mon, 29 Jan 2024 19:52:32 +0100 Subject: [PATCH] Fix CondExp codegen wrt. destruction of temporaries Fixes isse #4570. --- gen/toir.cpp | 4 ++-- tests/codegen/gh4570.d | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/codegen/gh4570.d 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()); +}