changeset 1326:a41a40deff73

Fixed dmdfe generated class invariant calls. Also insert proper "this !is null" check before it. Fixed invariant* dstress regressions and generally seems like a good idea. Hope I didn't break anything.. minitests run fine!
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sun, 10 May 2009 00:46:09 +0200
parents 5a9dc345c70a
children 49fd0c8040e6
files dmd/func.c gen/toir.cpp
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/func.c	Sat May 09 20:13:05 2009 +0200
+++ b/dmd/func.c	Sun May 10 00:46:09 2009 +0200
@@ -1232,6 +1232,7 @@
 	    if (addPreInvariant())
 	    {
 		Expression *e = NULL;
+                Expression *ee = NULL;
 		if (isDtorDeclaration())
 		{
 		    // Call invariant directly only if it exists
@@ -1256,11 +1257,30 @@
 		{   // Call invariant virtually
 		    ThisExp *v = new ThisExp(0);
 		    v->type = vthis->type;
+                    e = new AssertExp(loc, v, NULL);
+
+                    // LDC: check for null this
+                    v = new ThisExp(0);
+                    v->type = vthis->type;
+                    v->var = vthis;
+
+                    NullExp *nv = new NullExp(0);
+                    nv->type = v->type;
+
+                    IdentityExp *ie = new IdentityExp(TOKnotidentity, 0, v, nv);
+                    ie->type = Type::tbool;
+
 		    Expression *se = new StringExp(0, (char *)"null this");
 		    se = se->semantic(sc);
 		    se->type = Type::tchar->arrayOf();
-		    e = new AssertExp(loc, v, se);
+
+		    ee = new AssertExp(loc, ie, se);
 		}
+                if (ee)
+                {
+                    ExpStatement *s = new ExpStatement(0, ee);
+                    a->push(s);
+                }
 		if (e)
 		{
 		    ExpStatement *s = new ExpStatement(0, e);
--- a/gen/toir.cpp	Sat May 09 20:13:05 2009 +0200
+++ b/gen/toir.cpp	Sun May 10 00:46:09 2009 +0200
@@ -1753,9 +1753,8 @@
         LLValue* thisarg = p->func()->thisArg;
         assert(thisarg && "null thisarg, but we're in assert(this) exp;");
         LLValue* thisptr = DtoLoad(p->func()->thisArg);
-        LLValue* thisnotnull = p->ir->CreateIsNotNull(thisptr);
-        cond = new DImValue(Type::tbool, thisnotnull);
-        condty = Type::tbool;
+        condty = e1->type->toBasetype();
+        cond = new DImValue(condty, thisptr);
     }
     else
     {