Skip to content

Commit

Permalink
Fix CondExp codegen wrt. destruction of temporaries
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Jan 29, 2024
1 parent cbdce51 commit f3cb8dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,15 +2095,15 @@ 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()));
}
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()));
Expand Down
11 changes: 11 additions & 0 deletions tests/codegen/gh4570.d
Original file line number Diff line number Diff line change
@@ -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());
}

0 comments on commit f3cb8dc

Please sign in to comment.