Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d

Renamed some LLVM uses of ::create statics to ::Create , lower case ones will be deprecated soon.
This commit is contained in:
Tomas Lindquist Olsen 2008-10-14 13:21:14 +02:00
parent 202c4f7bc2
commit 180487b614
4 changed files with 29 additions and 13 deletions

View file

@ -1137,7 +1137,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
Logger::println("has nestedref set"); Logger::println("has nestedref set");
assert(vd->ir.irLocal); assert(vd->ir.irLocal);
// alloca as usual is no value already // alloca as usual if no value already
if (!vd->ir.irLocal->value) if (!vd->ir.irLocal->value)
{ {
vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars()); vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars());

View file

@ -1172,9 +1172,8 @@ void WithStatement::toIR(IRState* p)
assert(body); assert(body);
DValue* e = exp->toElem(p); DValue* e = exp->toElem(p);
assert(!wthis->ir.isSet());
wthis->ir.irLocal = new IrLocal(wthis); DtoDeclarationExp(wthis);
wthis->ir.irLocal->value = DtoAlloca(DtoType(wthis->type), wthis->toChars());
DtoStore(e->getRVal(), wthis->ir.irLocal->value); DtoStore(e->getRVal(), wthis->ir.irLocal->value);
body->toIR(p); body->toIR(p);

View file

@ -620,7 +620,7 @@ DValue* MinAssignExp::toElem(IRState* p)
Logger::println("ptr"); Logger::println("ptr");
LLValue* tmp = r->getRVal(); LLValue* tmp = r->getRVal();
LLValue* zero = llvm::ConstantInt::get(tmp->getType(),0,false); 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()); tmp = llvm::GetElementPtrInst::Create(l->getRVal(),tmp,"tmp",p->scopebb());
res = new DImValue(type, tmp); res = new DImValue(type, tmp);
} }
@ -1412,10 +1412,10 @@ DValue* PostExp::toElem(IRState* p)
assert(e2type->isintegral()); assert(e2type->isintegral());
LLValue* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); LLValue* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned());
if (op == TOKplusplus) { 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) { 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) else if (e1type->ty == Tpointer)
@ -1431,10 +1431,10 @@ DValue* PostExp::toElem(IRState* p)
assert(e2type->isfloating()); assert(e2type->isfloating());
LLValue* one = DtoConstFP(e1type, 1.0); LLValue* one = DtoConstFP(e1type, 1.0);
if (op == TOKplusplus) { 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) { else if (op == TOKminusminus) {
post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb()); post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb());
} }
} }
else else
@ -1700,7 +1700,7 @@ DValue* AndAndExp::toElem(IRState* p)
DValue* v = e2->toElem(p); DValue* v = e2->toElem(p);
LLValue* vbool = DtoBoolean(loc, v); 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); DtoStore(uandvbool,resval);
llvm::BranchInst::Create(andandend,p->scopebb()); llvm::BranchInst::Create(andandend,p->scopebb());
@ -1754,7 +1754,7 @@ DValue* X##Exp::toElem(IRState* p) \
LOG_SCOPE; \ LOG_SCOPE; \
DValue* u = e1->toElem(p); \ DValue* u = e1->toElem(p); \
DValue* v = e2->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); \ return new DImValue(type, x); \
} \ } \
\ \
@ -1766,7 +1766,7 @@ DValue* X##AssignExp::toElem(IRState* p) \
DValue* v = e2->toElem(p); \ DValue* v = e2->toElem(p); \
LLValue* uval = u->getRVal(); \ LLValue* uval = u->getRVal(); \
LLValue* vval = v->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()); \ DtoStore(DtoPointedType(u->getLVal(), tmp), u->getLVal()); \
return u; \ return u; \
} }
@ -2022,7 +2022,7 @@ DValue* ComExp::toElem(IRState* p)
LLValue* value = u->getRVal(); LLValue* value = u->getRVal();
LLValue* minusone = llvm::ConstantInt::get(value->getType(), -1, true); 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); return new DImValue(type, value);
} }

17
tests/mini/with2.d Normal file
View file

@ -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);
}