diff --git a/gen/functions.cpp b/gen/functions.cpp index d1115f15..fff942ad 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -87,11 +87,7 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, // member functions if (thistype) { - bool toref = (thistype->toBasetype()->ty == Tstruct); -#if STRUCTTHISREF - fty.is_arg_this_ref = toref; -#endif - fty.arg_this = new IrFuncTyArg(thistype, toref); + fty.arg_this = new IrFuncTyArg(thistype, thistype->toBasetype()->ty == Tstruct); lidx++; } @@ -712,7 +708,10 @@ void DtoDefineFunction(FuncDeclaration* fd) assert(thisvar); LLValue* thismem = thisvar; - if (!f->fty.is_arg_this_ref) { + #if STRUCTTHISREF + if (!f->fty.arg_this->byref) + #endif + { thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align? DtoStore(thisvar, thismem); irfunction->thisArg = thismem; @@ -722,6 +721,7 @@ void DtoDefineFunction(FuncDeclaration* fd) fd->vthis->ir.irParam = new IrParameter(fd->vthis); fd->vthis->ir.irParam->value = thismem; fd->vthis->ir.irParam->arg = f->fty.arg_this; + fd->vthis->ir.irParam->isVthis = true; DtoDwarfLocalVariable(thismem, fd->vthis); diff --git a/gen/nested.cpp b/gen/nested.cpp index 6804238e..670a0800 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -463,12 +463,19 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) { if (vd->isParameter()) { // Parameters will have storage associated with them (to handle byref etc.), // so handle those cases specially by storing a pointer instead of a value. - assert(vd->ir.irParam->value); - LLValue* value = vd->ir.irParam->value; + IrParameter * irparam = vd->ir.irParam; + LLValue* value = irparam->value; + assert(value); LLType* type = value->getType(); bool refout = vd->storage_class & (STCref | STCout); bool lazy = vd->storage_class & STClazy; - if (!refout && (!vd->ir.irParam->arg->byref || lazy)) { + bool byref = irparam->arg->byref; + #if STRUCTTHISREF + bool isVthisPtr = irparam->isVthis && !byref; + #else + bool isVthisPtr = irparam->isVthis; + #endif + if ((!refout && (!byref || lazy)) || isVthisPtr) { // This will be copied to the nesting frame. if (lazy) type = type->getContainedType(0); diff --git a/ir/irfuncty.h b/ir/irfuncty.h index 4806ccfc..00623cad 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -79,9 +79,6 @@ struct IrFuncTy : IrBase // range of normal parameters to reverse bool reverseParams; - // arg_this is reference - bool is_arg_this_ref; - IrFuncTy() : ret(NULL), args(), @@ -91,8 +88,7 @@ struct IrFuncTy : IrBase arg_arguments(NULL), arg_argptr(NULL), c_vararg(false), - reverseParams(false), - is_arg_this_ref(false) + reverseParams(false) {} #if defined(_MSC_VER) @@ -107,8 +103,7 @@ struct IrFuncTy : IrBase arg_arguments(rhs.arg_arguments), arg_argptr(rhs.arg_argptr), c_vararg(rhs.c_vararg), - reverseParams(rhs.reverseParams), - is_arg_this_ref(rhs.is_arg_this_ref) + reverseParams(rhs.reverseParams) {} IrFuncTy& operator=(const IrFuncTy& rhs) @@ -122,7 +117,6 @@ struct IrFuncTy : IrBase arg_argptr = rhs.arg_argptr; c_vararg = rhs.c_vararg; reverseParams = rhs.reverseParams; - is_arg_this_ref = rhs.is_arg_this_ref; return *this; } #endif diff --git a/ir/irvar.cpp b/ir/irvar.cpp index 24184529..f41f6acb 100644 --- a/ir/irvar.cpp +++ b/ir/irvar.cpp @@ -38,7 +38,7 @@ IrLocal::IrLocal(VarDeclaration* v) : IrVar(v) ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -IrParameter::IrParameter(VarDeclaration* v) : IrLocal(v), arg(0) +IrParameter::IrParameter(VarDeclaration* v) : IrLocal(v), arg(0), isVthis(false) { } diff --git a/ir/irvar.h b/ir/irvar.h index 8d5934d8..3d66cc39 100644 --- a/ir/irvar.h +++ b/ir/irvar.h @@ -38,6 +38,7 @@ struct IrParameter : IrLocal { IrParameter(VarDeclaration* v); IrFuncTyArg *arg; + bool isVthis; // true, if it is the 'this' parameter }; // represents an aggregate field variable