mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-19 21:23:22 +01:00
[svn r277] Fixed a nasty bug in delegate expressions. Context pointers to nested functions of the parent, from inside a nested function were
invalid.
This commit is contained in:
11
gen/toir.cpp
11
gen/toir.cpp
@@ -2230,13 +2230,12 @@ DValue* DelegateExp::toElem(IRState* p)
|
||||
DValue* u = e1->toElem(p);
|
||||
LLValue* uval;
|
||||
if (DFuncValue* f = u->isFunc()) {
|
||||
//assert(f->vthis);
|
||||
//uval = f->vthis;
|
||||
LLValue* nestvar = p->func()->decl->ir.irFunc->nestedVar;
|
||||
if (nestvar)
|
||||
uval = nestvar;
|
||||
assert(f->func);
|
||||
LLValue* contextptr = DtoNestedContext(f->func->toParent2()->isFuncDeclaration());
|
||||
if (!contextptr)
|
||||
uval = LLConstant::getNullValue(getVoidPtrType());
|
||||
else
|
||||
uval = llvm::ConstantPointerNull::get(int8ptrty);
|
||||
uval = DtoBitCast(contextptr, getVoidPtrType());
|
||||
}
|
||||
else {
|
||||
DValue* src = u;
|
||||
|
||||
12
tangotests/nested1.d
Normal file
12
tangotests/nested1.d
Normal file
@@ -0,0 +1,12 @@
|
||||
module tangotests.nested1;
|
||||
|
||||
void main()
|
||||
{
|
||||
int i = 42;
|
||||
assert(i == 42);
|
||||
void func()
|
||||
{
|
||||
assert(i == 42);
|
||||
}
|
||||
func();
|
||||
}
|
||||
32
tangotests/nested2.d
Normal file
32
tangotests/nested2.d
Normal file
@@ -0,0 +1,32 @@
|
||||
module tangotests.nested2;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main()
|
||||
{
|
||||
int var = 2;
|
||||
|
||||
void exec(void delegate() dg)
|
||||
{
|
||||
printf("var = %d\n", var);
|
||||
dg();
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
printf("var = %d\n", var);
|
||||
assert(var == 5);
|
||||
}
|
||||
|
||||
void bar()
|
||||
{
|
||||
printf("var = %d\n", var);
|
||||
var += 3;
|
||||
exec(&foo);
|
||||
}
|
||||
|
||||
printf("var = %d\n", var);
|
||||
exec(&bar);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user