# HG changeset patch # User Frits van Bommel # Date 1239932876 -7200 # Node ID b6370749ec8de8b0aba61dcdf0f630391244cb24 # Parent f41ff8ccc24986b84420abeb74dde7b4c9e9c500 Use 'undef' instead of null for unneeded contexts. diff -r f41ff8ccc249 -r b6370749ec8d gen/nested.cpp --- a/gen/nested.cpp Fri Apr 17 01:14:35 2009 +0200 +++ b/gen/nested.cpp Fri Apr 17 03:47:56 2009 +0200 @@ -228,19 +228,25 @@ { ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration(); if (!cd || !cd->vthis) - return getNullPtr(getVoidPtrType()); + return llvm::UndefValue::get(getVoidPtrType()); val = DtoLoad(irfunc->thisArg); val = DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis")); } else { - return getNullPtr(getVoidPtrType()); + return llvm::UndefValue::get(getVoidPtrType()); } if (nestedCtx == NCHybrid) { // If sym is a nested function, and it's parent context is different than the // one we got, adjust it. if (FuncDeclaration* fd = getParentFunc(sym->isFuncDeclaration(), true)) { + // if this is for a function that doesn't access variables from + // enclosing scopes, it doesn't matter what we pass. + // Tell LLVM about it by passing an 'undef'. + if (fd->ir.irFunc->depth == 0) + return llvm::UndefValue::get(getVoidPtrType()); + Logger::println("For nested function, parent is %s", fd->toChars()); FuncDeclaration* ctxfd = irfunc->decl; Logger::println("Current function is %s", ctxfd->toChars());