From f7e5245e03535977a7995623eaeb0bcba78c07cf Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Fri, 13 Jul 2012 11:38:56 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#138=20=E2=80=93=20in=20precondition=20of?= =?UTF-8?q?=20methods=20broken=20in=20D1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why the code was special-cased for D2 in the first place – are there any cases where we expect a »full« context struct in the contracts for D1. At least, they don't occur in DStress/Tango/…. As a general note, this is one of many bugs which would have not gone unnoticed if we didn't use so many bitcasts. --- gen/tocall.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/gen/tocall.cpp b/gen/tocall.cpp index ae54b345..6738b0e1 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -392,24 +392,26 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* // then comes a context argument... if(thiscall || delegatecall || nestedcall) { -#if DMDV2 - if (dfnval && (dfnval->func->ident == Id::ensure || dfnval->func->ident == Id::require)) { + if (dfnval && (dfnval->func->ident == Id::ensure || + dfnval->func->ident == Id::require)) + { + // ... which can be the this "context" argument for a contract + // invocation (we do not generate a full nested context struct for + // these) LLValue* thisarg = DtoBitCast(DtoLoad(gIR->func()->thisArg), getVoidPtrType()); ++argiter; args.push_back(thisarg); } - else -#endif - // ... which can be a 'this' argument - if (thiscall && dfnval && dfnval->vthis) - { + else if (thiscall && dfnval && dfnval->vthis) + { + // ... or a normal 'this' argument LLValue* thisarg = DtoBitCast(dfnval->vthis, *argiter); ++argiter; args.push_back(thisarg); } - // ... or a delegate context arg else if (delegatecall) { + // ... or a delegate context arg LLValue* ctxarg; if (fnval->isLVal()) { @@ -423,9 +425,9 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* ++argiter; args.push_back(ctxarg); } - // ... or a nested function context arg else if (nestedcall) { + /// ... or a nested function context arg if (dfnval) { LLValue* contextptr = DtoNestedContext(loc, dfnval->func); contextptr = DtoBitCast(contextptr, getVoidPtrType());