From 8b783da5234291f0bda83faaf8334f477eb2a43e Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Wed, 10 Jul 2013 18:15:05 +0400 Subject: [PATCH] Fixed cases where the destructor is called on an uninitialized temporary --- gen/toir.cpp | 49 ++++++++++++++++++++++++------------------ tests/d2/dmd-testsuite | 2 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 4abf9c0e..99247fe8 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -115,33 +115,40 @@ DValue *Expression::toElemDtor(IRState *p) apply(&CallDestructors::searchVarsWithDesctructors, &edtors); if (!edtors.empty()) { - // create finally block that calls destructors on temporaries - CallDestructors *callDestructors = new CallDestructors(edtors); + if (op == TOKcall) { + // create finally block that calls destructors on temporaries + CallDestructors *callDestructors = new CallDestructors(edtors); - // create landing pad - llvm::BasicBlock *oldend = p->scopeend(); - llvm::BasicBlock *landingpadbb = llvm::BasicBlock::Create(gIR->context(), "landingpad", p->topfunc(), oldend); + // create landing pad + llvm::BasicBlock *oldend = p->scopeend(); + llvm::BasicBlock *landingpadbb = llvm::BasicBlock::Create(gIR->context(), "landingpad", p->topfunc(), oldend); - // set up the landing pad - IRLandingPad& pad = gIR->func()->gen->landingPadInfo; - pad.addFinally(callDestructors); - pad.push(landingpadbb); + // set up the landing pad + IRLandingPad &pad = gIR->func()->gen->landingPadInfo; + pad.addFinally(callDestructors); + pad.push(landingpadbb); - // evaluate the expression - DValue *val = toElem(p); + // evaluate the expression + DValue *val = toElem(p); - // build the landing pad - llvm::BasicBlock *oldbb = p->scopebb(); - pad.pop(); + // build the landing pad + llvm::BasicBlock *oldbb = p->scopebb(); + pad.pop(); - // call the destructors - gIR->scope() = IRScope(oldbb, oldend); - callDestructors->toIR(); - delete callDestructors; - return val; - } else { - return toElem(p); + // call the destructors + gIR->scope() = IRScope(oldbb, oldend); + callDestructors->toIR(); + delete callDestructors; + return val; + } else { + DValue *val = toElem(p); + CallDestructors(edtors).toIR(); + return val; + } } + + return toElem(p); + } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tests/d2/dmd-testsuite b/tests/d2/dmd-testsuite index 48e8b097..e8c14b05 160000 --- a/tests/d2/dmd-testsuite +++ b/tests/d2/dmd-testsuite @@ -1 +1 @@ -Subproject commit 48e8b097f3660df83bd01f79e6e0cda4cee48764 +Subproject commit e8c14b05ca3e3642c2fe343a912cd2e800864414