diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 9df3526c..90376ee9 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1137,7 +1137,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration) Logger::println("has nestedref set"); assert(vd->ir.irLocal); - // alloca as usual is no value already + // alloca as usual if no value already if (!vd->ir.irLocal->value) { vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars()); diff --git a/gen/statements.cpp b/gen/statements.cpp index 23c1e4a7..8e43b87c 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -1172,9 +1172,8 @@ void WithStatement::toIR(IRState* p) assert(body); DValue* e = exp->toElem(p); - assert(!wthis->ir.isSet()); - wthis->ir.irLocal = new IrLocal(wthis); - wthis->ir.irLocal->value = DtoAlloca(DtoType(wthis->type), wthis->toChars()); + + DtoDeclarationExp(wthis); DtoStore(e->getRVal(), wthis->ir.irLocal->value); body->toIR(p); diff --git a/gen/toir.cpp b/gen/toir.cpp index 63d80185..53b7de79 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -620,7 +620,7 @@ DValue* MinAssignExp::toElem(IRState* p) Logger::println("ptr"); LLValue* tmp = r->getRVal(); LLValue* zero = llvm::ConstantInt::get(tmp->getType(),0,false); - tmp = llvm::BinaryOperator::createSub(zero,tmp,"tmp",p->scopebb()); + tmp = llvm::BinaryOperator::CreateSub(zero,tmp,"tmp",p->scopebb()); tmp = llvm::GetElementPtrInst::Create(l->getRVal(),tmp,"tmp",p->scopebb()); res = new DImValue(type, tmp); } @@ -1412,10 +1412,10 @@ DValue* PostExp::toElem(IRState* p) assert(e2type->isintegral()); LLValue* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); if (op == TOKplusplus) { - post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); + post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb()); } else if (op == TOKminusminus) { - post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); + post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb()); } } else if (e1type->ty == Tpointer) @@ -1431,10 +1431,10 @@ DValue* PostExp::toElem(IRState* p) assert(e2type->isfloating()); LLValue* one = DtoConstFP(e1type, 1.0); if (op == TOKplusplus) { - post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); + post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb()); } else if (op == TOKminusminus) { - post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); + post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb()); } } else @@ -1700,7 +1700,7 @@ DValue* AndAndExp::toElem(IRState* p) DValue* v = e2->toElem(p); LLValue* vbool = DtoBoolean(loc, v); - LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); + LLValue* uandvbool = llvm::BinaryOperator::Create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); DtoStore(uandvbool,resval); llvm::BranchInst::Create(andandend,p->scopebb()); @@ -1754,7 +1754,7 @@ DValue* X##Exp::toElem(IRState* p) \ LOG_SCOPE; \ DValue* u = e1->toElem(p); \ DValue* v = e2->toElem(p); \ - LLValue* x = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ + LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ return new DImValue(type, x); \ } \ \ @@ -1766,7 +1766,7 @@ DValue* X##AssignExp::toElem(IRState* p) \ DValue* v = e2->toElem(p); \ LLValue* uval = u->getRVal(); \ LLValue* vval = v->getRVal(); \ - LLValue* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ + LLValue* tmp = llvm::BinaryOperator::Create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ DtoStore(DtoPointedType(u->getLVal(), tmp), u->getLVal()); \ return u; \ } @@ -2022,7 +2022,7 @@ DValue* ComExp::toElem(IRState* p) LLValue* value = u->getRVal(); LLValue* minusone = llvm::ConstantInt::get(value->getType(), -1, true); - value = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); + value = llvm::BinaryOperator::Create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); return new DImValue(type, value); } diff --git a/tests/mini/with2.d b/tests/mini/with2.d new file mode 100644 index 00000000..bef3d6ea --- /dev/null +++ b/tests/mini/with2.d @@ -0,0 +1,17 @@ +struct bar { + int bar; +} + +void main() { + bar Bar; + with (Bar) + { + assert(Bar.bar == 0); + void test() + { + bar ++; + } + test(); + } + assert(Bar.bar == 1); +}