changeset 399:0e6b4d65d3f8

Give error messages for invalid casts. This required passing Loc information to certain functions. Fixes nocompile/b/bug_cgcs_354_A/B.
author Christian Kamm <kamm incasoftware de>
date Sat, 26 Jul 2008 17:19:16 +0200
parents 811f82dfddbd
children e6e972c5cc17
files gen/aa.cpp gen/aa.h gen/arrays.cpp gen/arrays.h gen/complex.cpp gen/complex.h gen/functions.cpp gen/llvmhelpers.cpp gen/llvmhelpers.h gen/statements.cpp gen/toir.cpp
diffstat 11 files changed, 133 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/gen/aa.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/aa.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -14,7 +14,7 @@
 
 // makes sure the key value lives in memory so it can be passed to the runtime functions without problems
 // returns the pointer
-static LLValue* to_pkey(DValue* key)
+static LLValue* to_pkey(Loc& loc, DValue* key)
 {
     Type* keytype = key->getType();
     bool needmem = !DtoIsPassedByRef(keytype);
@@ -38,7 +38,7 @@
     else {
         LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
         DVarValue* var = new DVarValue(keytype, tmp, true);
-        DtoAssign(var, key);
+        DtoAssign(loc, var, key);
         return tmp;
     }
 
@@ -62,7 +62,7 @@
 
 /////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
+DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key)
 {
     // call:
     // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize)
@@ -83,7 +83,7 @@
     LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type)));
 
     // pkey param
-    LLValue* pkey = to_pkey(key);
+    LLValue* pkey = to_pkey(loc, key);
     pkey = DtoBitCast(pkey, funcTy->getParamType(3));
 
     // call runtime
@@ -99,7 +99,7 @@
 
 /////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoAAIn(Type* type, DValue* aa, DValue* key)
+DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
 {
     // call:
     // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
@@ -121,7 +121,7 @@
     keyti = DtoBitCast(keyti, funcTy->getParamType(1));
 
     // pkey param
-    LLValue* pkey = to_pkey(key);
+    LLValue* pkey = to_pkey(loc, key);
     pkey = DtoBitCast(pkey, funcTy->getParamType(2));
 
     // call runtime
@@ -137,7 +137,7 @@
 
 /////////////////////////////////////////////////////////////////////////////////////
 
-void DtoAARemove(DValue* aa, DValue* key)
+void DtoAARemove(Loc& loc, DValue* aa, DValue* key)
 {
     // call:
     // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey)
@@ -159,7 +159,7 @@
     keyti = DtoBitCast(keyti, funcTy->getParamType(1));
 
     // pkey param
-    LLValue* pkey = to_pkey(key);
+    LLValue* pkey = to_pkey(loc, key);
     pkey = DtoBitCast(pkey, funcTy->getParamType(2));
 
     // build arg vector
--- a/gen/aa.h	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/aa.h	Sat Jul 26 17:19:16 2008 +0200
@@ -1,8 +1,8 @@
 #ifndef LLVMDC_GEN_AA_H
 #define LLVMDC_GEN_AA_H
 
-DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key);
-DValue* DtoAAIn(Type* type, DValue* aa, DValue* key);
-void DtoAARemove(DValue* aa, DValue* key);
+DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key);
+DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key);
+void DtoAARemove(Loc& loc, DValue* aa, DValue* key);
 
 #endif // LLVMDC_GEN_AA_H
--- a/gen/arrays.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/arrays.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -106,7 +106,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-void DtoArrayInit(DValue* array, DValue* value)
+void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
 {
     Logger::println("DtoArrayInit");
     LOG_SCOPE;
@@ -120,7 +120,7 @@
     {
         val = new llvm::AllocaInst(DtoType(value->getType()), ".tmpparam", gIR->topallocapoint());
         DVarValue lval(value->getType(), val, true);
-        DtoAssign(&lval, value);
+        DtoAssign(loc, &lval, value);
     }
     else
     {
@@ -531,7 +531,7 @@
     DValue* e = exp->toElem(gIR);
 
     if (!e->inPlace())
-        DtoAssign(dptr, e);
+        DtoAssign(exp->loc, dptr, e);
 
     return slice;
 }
@@ -633,7 +633,7 @@
         LLValue* mem = slice->ptr;
 
         DVarValue* memval = new DVarValue(e1->getType(), mem, true);
-        DtoAssign(memval, e1);
+        DtoAssign(exp1->loc, memval, e1);
 
         src1 = DtoArrayPtr(e2);
 
@@ -664,7 +664,7 @@
 
         mem = gIR->ir->CreateGEP(mem,len1,"tmp");
         DVarValue* memval = new DVarValue(e2->getType(), mem, true);
-        DtoAssign(memval, e2);
+        DtoAssign(exp1->loc, memval, e2);
 
         return slice;
     }
--- a/gen/arrays.h	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/arrays.h	Sat Jul 26 17:19:16 2008 +0200
@@ -14,7 +14,7 @@
 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src);
 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src);
 
-void DtoArrayInit(DValue* array, DValue* value);
+void DtoArrayInit(Loc& loc, DValue* array, DValue* value);
 void DtoArrayAssign(LLValue* l, LLValue* r);
 void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr);
 void DtoSetArrayToNull(LLValue* v);
--- a/gen/complex.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/complex.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -101,12 +101,12 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplex(Type* to, DValue* val)
+DValue* DtoComplex(Loc& loc, Type* to, DValue* val)
 {
     Type* t = DtoDType(val->getType());
 
     if (val->isComplex() || t->iscomplex()) {
-        return DtoCastComplex(val, to);
+        return DtoCastComplex(loc, val, to);
     }
 
     const LLType* base = DtoComplexBaseType(to);
@@ -126,13 +126,13 @@
     }
 
     if (t->isimaginary()) {
-        return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(val, baseimty)->getRVal());
+        return new DComplexValue(to, LLConstant::getNullValue(DtoType(baserety)), DtoCastFloat(loc, val, baseimty)->getRVal());
     }
     else if (t->isfloating()) {
-        return new DComplexValue(to, DtoCastFloat(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty)));
+        return new DComplexValue(to, DtoCastFloat(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty)));
     }
     else if (t->isintegral()) {
-        return new DComplexValue(to, DtoCastInt(val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty)));
+        return new DComplexValue(to, DtoCastInt(loc, val, baserety)->getRVal(), LLConstant::getNullValue(DtoType(baseimty)));
     }
     assert(0);
 }
@@ -179,10 +179,10 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs)
+DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs)
 {
-    lhs = DtoComplex(type, resolveLR(lhs, true));
-    rhs = DtoComplex(type, resolveLR(rhs, false));
+    lhs = DtoComplex(loc, type, resolveLR(lhs, true));
+    rhs = DtoComplex(loc, type, resolveLR(rhs, false));
 
     llvm::Value *a, *b, *c, *d, *re, *im;
 
@@ -200,10 +200,10 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs)
+DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs)
 {
-    lhs = DtoComplex(type, resolveLR(lhs, true));
-    rhs = DtoComplex(type, resolveLR(rhs, false));
+    lhs = DtoComplex(loc, type, resolveLR(lhs, true));
+    rhs = DtoComplex(loc, type, resolveLR(rhs, false));
 
     llvm::Value *a, *b, *c, *d, *re, *im;
 
@@ -221,10 +221,10 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs)
+DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs)
 {
-    lhs = DtoComplex(type, resolveLR(lhs, true));
-    rhs = DtoComplex(type, resolveLR(rhs, false));
+    lhs = DtoComplex(loc, type, resolveLR(lhs, true));
+    rhs = DtoComplex(loc, type, resolveLR(rhs, false));
 
     llvm::Value *a, *b, *c, *d;
 
@@ -248,10 +248,10 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs)
+DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs)
 {
-    lhs = DtoComplex(type, resolveLR(lhs, true));
-    rhs = DtoComplex(type, resolveLR(rhs, false));
+    lhs = DtoComplex(loc, type, resolveLR(lhs, true));
+    rhs = DtoComplex(loc, type, resolveLR(rhs, false));
 
     llvm::Value *a, *b, *c, *d;
 
@@ -281,9 +281,9 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoComplexNeg(Type* type, DValue* val)
+DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val)
 {
-    val = DtoComplex(type, resolveLR(val, false));
+    val = DtoComplex(loc, type, resolveLR(val, false));
 
     llvm::Value *a, *b, *re, *im;
 
@@ -299,12 +299,12 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
+LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs)
 {
     Type* type = lhs->getType();
 
-    lhs = DtoComplex(type, resolveLR(lhs, false));
-    rhs = DtoComplex(type, resolveLR(rhs, false));
+    lhs = DtoComplex(loc, type, resolveLR(lhs, false));
+    rhs = DtoComplex(loc, type, resolveLR(rhs, false));
 
     llvm::Value *a, *b, *c, *d;
 
@@ -332,7 +332,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoCastComplex(DValue* val, Type* _to)
+DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to)
 {
     Type* to = DtoDType(_to);
     Type* vty = val->getType();
@@ -370,14 +370,14 @@
             return new DImValue(to, val->isComplex()->im);
         LLValue* v = val->getRVal();
         DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp")));
-        return DtoCastFloat(im, to);
+        return DtoCastFloat(loc, im, to);
     }
     else if (to->isfloating()) {
         if (val->isComplex())
             return new DImValue(to, val->isComplex()->re);
         LLValue* v = val->getRVal();
         DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp")));
-        return DtoCastFloat(re, to);
+        return DtoCastFloat(loc, re, to);
     }
     else
     assert(0);
--- a/gen/complex.h	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/complex.h	Sat Jul 26 17:19:16 2008 +0200
@@ -11,21 +11,21 @@
 
 LLValue* DtoRealPart(DValue* val);
 LLValue* DtoImagPart(DValue* val);
-DValue* DtoComplex(Type* to, DValue* val);
+DValue* DtoComplex(Loc& loc, Type* to, DValue* val);
 
 void DtoComplexAssign(LLValue* l, LLValue* r);
 void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im);
 
 void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im);
 
-DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs);
-DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs);
-DValue* DtoComplexMul(Type* type, DValue* lhs, DValue* rhs);
-DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs);
-DValue* DtoComplexNeg(Type* type, DValue* val);
+DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs);
+DValue* DtoComplexSub(Loc& loc, Type* type, DValue* lhs, DValue* rhs);
+DValue* DtoComplexMul(Loc& loc, Type* type, DValue* lhs, DValue* rhs);
+DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs);
+DValue* DtoComplexNeg(Loc& loc, Type* type, DValue* val);
 
-LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs);
+LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs);
 
-DValue* DtoCastComplex(DValue* val, Type* to);
+DValue* DtoCastComplex(Loc& loc, DValue* val, Type* to);
 
 #endif // LLVMDC_GEN_COMPLEX_H
--- a/gen/functions.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/functions.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -793,7 +793,7 @@
     {
         LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint());
         DVarValue* vv = new DVarValue(argexp->type, alloc, true);
-        DtoAssign(vv, arg);
+        DtoAssign(argexp->loc, vv, arg);
         arg = vv;
     }
 
@@ -807,7 +807,7 @@
     Logger::println("DtoVariadicArgument");
     LOG_SCOPE;
     DVarValue vv(argexp->type, dst, true);
-    DtoAssign(&vv, argexp->toElem(gIR));
+    DtoAssign(argexp->loc, &vv, argexp->toElem(gIR));
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/llvmhelpers.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/llvmhelpers.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -512,7 +512,7 @@
 // ASSIGNMENT HELPER (store this in that)
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
-void DtoAssign(DValue* lhs, DValue* rhs)
+void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs)
 {
     Logger::cout() << "DtoAssign(...);\n";
     LOG_SCOPE;
@@ -536,7 +536,7 @@
                 DtoArrayCopySlices(s, s2);
             }
             else if (t->next->toBasetype()->equals(t2)) {
-                DtoArrayInit(s, rhs);
+                DtoArrayInit(loc, s, rhs);
             }
             else {
                 DtoArrayCopyToSlice(s, rhs);
@@ -561,7 +561,7 @@
             DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal());
         }
         else {
-            DtoArrayInit(lhs, rhs);
+            DtoArrayInit(loc, lhs, rhs);
         }
     }
     else if (t->ty == Tdelegate) {
@@ -596,7 +596,7 @@
         LLValue* dst;
         if (DLRValue* lr = lhs->isLRValue()) {
             dst = lr->getLVal();
-            rhs = DtoCastComplex(rhs, lr->getLType());
+            rhs = DtoCastComplex(loc, rhs, lr->getLType());
         }
         else {
             dst = lhs->getRVal();
@@ -616,10 +616,10 @@
             // handle lvalue cast assignments
             if (DLRValue* lr = lhs->isLRValue()) {
                 Logger::println("lvalue cast!");
-                r = DtoCast(rhs, lr->getLType())->getRVal();
+                r = DtoCast(loc, rhs, lr->getLType())->getRVal();
             }
             else {
-                r = DtoCast(rhs, lhs->getType())->getRVal();
+                r = DtoCast(loc, rhs, lhs->getType())->getRVal();
             }
             Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
             assert(r->getType() == l->getType()->getContainedType(0));
@@ -676,7 +676,7 @@
 //      CASTING HELPERS
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
-DValue* DtoCastInt(DValue* val, Type* _to)
+DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to)
 {
     const LLType* tolltype = DtoType(_to);
 
@@ -709,7 +709,7 @@
         }
     }
     else if (to->iscomplex()) {
-        return DtoComplex(to, val);
+        return DtoComplex(loc, to, val);
     }
     else if (to->isfloating()) {
         if (from->isunsigned()) {
@@ -724,13 +724,14 @@
         rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp");
     }
     else {
-        assert(0 && "bad int cast");
+        error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), _to->toChars());
+        fatal();
     }
 
     return new DImValue(_to, rval);
 }
 
-DValue* DtoCastPtr(DValue* val, Type* to)
+DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to)
 {
     const LLType* tolltype = DtoType(to);
 
@@ -749,14 +750,14 @@
         rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
     }
     else {
-        Logger::println("invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
-        assert(0);
+        error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
+        fatal();
     }
 
     return new DImValue(to, rval);
 }
 
-DValue* DtoCastFloat(DValue* val, Type* to)
+DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to)
 {
     if (val->getType() == to)
         return val;
@@ -773,7 +774,7 @@
     LLValue* rval;
 
     if (totype->iscomplex()) {
-        return DtoComplex(to, val);
+        return DtoComplex(loc, to, val);
     }
     else if (totype->isfloating()) {
         if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) {
@@ -789,7 +790,8 @@
             rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
         }
         else {
-            assert(0 && "bad float cast");
+            error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
+            fatal();
         }
     }
     else if (totype->isintegral()) {
@@ -801,24 +803,25 @@
         }
     }
     else {
-        assert(0 && "bad float cast");
+        error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
+        fatal();
     }
 
     return new DImValue(to, rval);
 }
 
-DValue* DtoCast(DValue* val, Type* to)
+DValue* DtoCast(Loc& loc, DValue* val, Type* to)
 {
     Type* fromtype = DtoDType(val->getType());
     Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
     if (fromtype->isintegral()) {
-        return DtoCastInt(val, to);
+        return DtoCastInt(loc, val, to);
     }
     else if (fromtype->iscomplex()) {
-        return DtoCastComplex(val, to);
+        return DtoCastComplex(loc, val, to);
     }
     else if (fromtype->isfloating()) {
-        return DtoCastFloat(val, to);
+        return DtoCastFloat(loc, val, to);
     }
     else if (fromtype->ty == Tclass) {
         return DtoCastClass(val, to);
@@ -827,10 +830,11 @@
         return DtoCastArray(val, to);
     }
     else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) {
-        return DtoCastPtr(val, to);
+        return DtoCastPtr(loc, val, to);
     }
     else {
-        assert(0);
+        error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
+        fatal();
     }
 }
 
@@ -872,7 +876,7 @@
     DValue* ie = DtoInitializer(init);
     if (!ie->inPlace()) {
         DValue* dst = new DVarValue(t, gvar, true);
-        DtoAssign(dst, ie);
+        DtoAssign(init->loc, dst, ie);
     }
     gIR->ir->CreateStore(DtoConstBool(true), gflag);
     gIR->ir->CreateBr(endinitbb);
@@ -1359,7 +1363,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-LLValue* DtoBoolean(DValue* dval)
+LLValue* DtoBoolean(Loc& loc, DValue* dval)
 {
     Type* dtype = dval->getType()->toBasetype();
     TY ty = dtype->ty;
@@ -1378,7 +1382,7 @@
     // complex
     else if (dtype->iscomplex())
     {
-        return DtoComplexEquals(TOKnotequal, dval, DtoNullValue(dtype));
+        return DtoComplexEquals(loc, TOKnotequal, dval, DtoNullValue(dtype));
     }
     // floating point
     else if (dtype->isfloating())
--- a/gen/llvmhelpers.h	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/llvmhelpers.h	Sat Jul 26 17:19:16 2008 +0200
@@ -39,16 +39,16 @@
 LLValue* DtoNestedVariable(VarDeclaration* vd);
 
 // basic operations
-void DtoAssign(DValue* lhs, DValue* rhs);
+void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs);
 
 // create a null dvalue
 DValue* DtoNullValue(Type* t);
 
 // casts
-DValue* DtoCastInt(DValue* val, Type* to);
-DValue* DtoCastPtr(DValue* val, Type* to);
-DValue* DtoCastFloat(DValue* val, Type* to);
-DValue* DtoCast(DValue* val, Type* to);
+DValue* DtoCastInt(Loc& loc, DValue* val, Type* to);
+DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to);
+DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to);
+DValue* DtoCast(Loc& loc, DValue* val, Type* to);
 
 // is template instance check
 bool DtoIsTemplateInstance(Dsymbol* s);
@@ -102,6 +102,6 @@
 DValue* DtoCallDFunc(FuncDeclaration* fdecl, Array* arguments, TypeClass* type=0, LLValue* thismem=0);
 
 /// Converts any value to a boolean (llvm i1)
-LLValue* DtoBoolean(DValue* dval);
+LLValue* DtoBoolean(Loc& loc, DValue* dval);
 
 #endif
--- a/gen/statements.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/statements.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -67,7 +67,7 @@
             DValue* e = exp->toElem(p);
 
             if (!e->inPlace())
-                DtoAssign(rvar, e);
+                DtoAssign(loc, rvar, e);
 
             DtoEnclosingHandlers(enclosinghandler, NULL);
 
@@ -160,7 +160,7 @@
 
     if (cond_val->getType() != LLType::Int1Ty) {
         Logger::cout() << "if conditional: " << *cond_val << '\n';
-        cond_val = DtoBoolean(cond_e);
+        cond_val = DtoBoolean(loc, cond_e);
     }
     LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb());
 
@@ -248,7 +248,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e);
+    LLValue* cond_val = DtoBoolean(loc, cond_e);
     delete cond_e;
 
     // conditional branch
@@ -299,7 +299,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e);
+    LLValue* cond_val = DtoBoolean(loc, cond_e);
     delete cond_e;
 
     // conditional branch
@@ -341,7 +341,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e);
+    LLValue* cond_val = DtoBoolean(loc, cond_e);
     delete cond_e;
 
     // conditional branch
@@ -677,7 +677,7 @@
         // give storage
         llval = new llvm::AllocaInst(DtoType(e->type), "tmp", gIR->topallocapoint());
         DVarValue* vv = new DVarValue(e->type, llval, true);
-        DtoAssign(vv, val);
+        DtoAssign(e->loc, vv, val);
     }
     else
     {
@@ -994,7 +994,7 @@
     if (!value->isRef() && !value->isOut()) {
         DValue* dst = new DVarValue(value->type, valvar, true);
         DValue* src = new DVarValue(value->type, value->ir.irLocal->value, true);
-        DtoAssign(dst, src);
+        DtoAssign(loc, dst, src);
         value->ir.irLocal->value = valvar;
     }
 
--- a/gen/toir.cpp	Sat Jul 26 15:42:05 2008 +0200
+++ b/gen/toir.cpp	Sat Jul 26 17:19:16 2008 +0200
@@ -568,7 +568,7 @@
         DVarValue arrval(ale->e1->type, arr->getLVal(), true);
         DValue* newlen = e2->toElem(p);
         DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen);
-        DtoAssign(&arrval, slice);
+        DtoAssign(loc, &arrval, slice);
         return newlen;
     }
 
@@ -576,7 +576,7 @@
 
     DValue* l = e1->toElem(p);
     DValue* r = e2->toElem(p);
-    DtoAssign(l, r);
+    DtoAssign(loc, l, r);
 
     if (l->isSlice() || l->isComplex())
         return l;
@@ -630,12 +630,12 @@
             return new DImValue(type, v);
         }
         else if (t->iscomplex()) {
-            return DtoComplexAdd(type, l, r);
+            return DtoComplexAdd(loc, type, l, r);
         }
         assert(0);
     }
     else if (t->iscomplex()) {
-        return DtoComplexAdd(type, l, r);
+        return DtoComplexAdd(loc, type, l, r);
     }
     else {
         return DtoBinAdd(l,r);
@@ -660,12 +660,12 @@
         res = new DImValue(type, gep);
     }
     else if (t->iscomplex()) {
-        res = DtoComplexAdd(e1->type, l, r);
+        res = DtoComplexAdd(loc, e1->type, l, r);
     }
     else {
         res = DtoBinAdd(l,r);
     }
-    DtoAssign(l, res);
+    DtoAssign(loc, l, res);
 
     return res;
 }
@@ -701,7 +701,7 @@
         return new DImValue(type, v);
     }
     else if (t->iscomplex()) {
-        return DtoComplexSub(type, l, r);
+        return DtoComplexSub(loc, type, l, r);
     }
     else {
         return DtoBinSub(l,r);
@@ -731,13 +731,13 @@
     }
     else if (t->iscomplex()) {
         Logger::println("complex");
-        res = DtoComplexSub(type, l, r);
+        res = DtoComplexSub(loc, type, l, r);
     }
     else {
         Logger::println("basic");
         res = DtoBinSub(l,r);
     }
-    DtoAssign(l, res);
+    DtoAssign(loc, l, res);
 
     return res;
 }
@@ -753,7 +753,7 @@
     DValue* r = e2->toElem(p);
 
     if (type->iscomplex()) {
-        return DtoComplexMul(type, l, r);
+        return DtoComplexMul(loc, type, l, r);
     }
 
     return DtoBinMul(l,r);
@@ -771,12 +771,12 @@
 
     DValue* res;
     if (type->iscomplex()) {
-        res = DtoComplexMul(type, l, r);
+        res = DtoComplexMul(loc, type, l, r);
     }
     else {
         res = DtoBinMul(l,r);
     }
-    DtoAssign(l, res);
+    DtoAssign(loc, l, res);
 
     return res;
 }
@@ -792,7 +792,7 @@
     DValue* r = e2->toElem(p);
 
     if (type->iscomplex()) {
-        return DtoComplexDiv(type, l, r);
+        return DtoComplexDiv(loc, type, l, r);
     }
 
     return DtoBinDiv(l, r);
@@ -810,12 +810,12 @@
 
     DValue* res;
     if (type->iscomplex()) {
-        res = DtoComplexDiv(type, l, r);
+        res = DtoComplexDiv(loc, type, l, r);
     }
     else {
         res = DtoBinDiv(l,r);
     }
-    DtoAssign(l, res);
+    DtoAssign(loc, l, res);
 
     return res;
 }
@@ -844,7 +844,7 @@
     DValue* r = e2->toElem(p);
 
     DValue* res = DtoBinRem(l, r);
-    DtoAssign(l, res);
+    DtoAssign(loc, l, res);
 
     return res;
 }
@@ -933,7 +933,7 @@
             Expression* exp = (Expression*)arguments->data[0];
             DValue* expv = exp->toElem(p);
             if (expv->getType()->toBasetype()->ty != Tint32)
-                expv = DtoCast(expv, Type::tint32);
+                expv = DtoCast(loc, expv, Type::tint32);
             LLValue* alloc = new llvm::AllocaInst(LLType::Int8Ty, expv->getRVal(), "alloca", p->scopebb());
             // done
             return new DImValue(type, alloc);
@@ -1208,7 +1208,7 @@
     LOG_SCOPE;
 
     DValue* u = e1->toElem(p);
-    DValue* v = DtoCast(u, to);
+    DValue* v = DtoCast(loc, u, to);
     // force d type to this->type
     v->getType() = type;
 
@@ -1437,7 +1437,7 @@
         arrptr = DtoGEP1(arrptr,r->getRVal());
     }
     else if (e1type->ty == Taarray) {
-        return DtoAAIndex(type, l, r);
+        return DtoAAIndex(loc, type, l, r);
     }
     else {
         Logger::println("invalid index exp! e1type: %s", e1type->toChars());
@@ -1671,7 +1671,7 @@
     else if (t->iscomplex())
     {
         Logger::println("complex");
-        eval = DtoComplexEquals(op, l, r);
+        eval = DtoComplexEquals(loc, op, l, r);
     }
     else if (t->isfloating())
     {
@@ -1837,7 +1837,7 @@
         // default initialize
         Expression* exp = newtype->defaultInit(loc);
         DValue* iv = exp->toElem(gIR);
-        DtoAssign(&tmpvar, iv);
+        DtoAssign(loc, &tmpvar, iv);
 
         // return as pointer-to
         return new DImValue(type, mem, false);
@@ -1934,7 +1934,7 @@
     llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend);
 
     // test condition
-    LLValue* condval = DtoBoolean(cond);
+    LLValue* condval = DtoBoolean(loc, cond);
 
     // branch
     llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb());
@@ -1963,7 +1963,7 @@
 
     DValue* u = e1->toElem(p);
 
-    LLValue* b = DtoBoolean(u);
+    LLValue* b = DtoBoolean(loc, u);
 
     LLConstant* zero = DtoConstBool(false);
     b = p->ir->CreateICmpEQ(b,zero);
@@ -1989,14 +1989,14 @@
     llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend);
     llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend);
 
-    LLValue* ubool = DtoBoolean(u);
+    LLValue* ubool = DtoBoolean(loc, u);
     DtoStore(ubool,resval);
     llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb());
 
     p->scope() = IRScope(andand, andandend);
     DValue* v = e2->toElem(p);
 
-    LLValue* vbool = DtoBoolean(v);
+    LLValue* vbool = DtoBoolean(loc, v);
     LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb());
     DtoStore(uandvbool,resval);
     llvm::BranchInst::Create(andandend,p->scopebb());
@@ -2025,14 +2025,14 @@
     llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend);
     llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend);
 
-    LLValue* ubool = DtoBoolean(u);
+    LLValue* ubool = DtoBoolean(loc, u);
     DtoStore(ubool,resval);
     llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb());
 
     p->scope() = IRScope(oror, ororend);
     DValue* v = e2->toElem(p);
 
-    LLValue* vbool = DtoBoolean(v);
+    LLValue* vbool = DtoBoolean(loc, v);
     DtoStore(vbool,resval);
     llvm::BranchInst::Create(ororend,p->scopebb());
 
@@ -2289,17 +2289,17 @@
     llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend);
 
     DValue* c = econd->toElem(p);
-    LLValue* cond_val = DtoBoolean(c);
+    LLValue* cond_val = DtoBoolean(loc, c);
     llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb());
 
     p->scope() = IRScope(condtrue, condfalse);
     DValue* u = e1->toElem(p);
-    DtoAssign(dvv, u);
+    DtoAssign(loc, dvv, u);
     llvm::BranchInst::Create(condend,p->scopebb());
 
     p->scope() = IRScope(condfalse, condend);
     DValue* v = e2->toElem(p);
-    DtoAssign(dvv, v);
+    DtoAssign(loc, dvv, v);
     llvm::BranchInst::Create(condend,p->scopebb());
 
     p->scope() = IRScope(condend, oldend);
@@ -2332,7 +2332,7 @@
     DValue* l = e1->toElem(p);
 
     if (type->iscomplex()) {
-        return DtoComplexNeg(type, l);
+        return DtoComplexNeg(loc, type, l);
     }
 
     LLValue* val = l->getRVal();
@@ -2390,11 +2390,11 @@
 
     if (e2type == elemtype) {
         DSliceValue* slice = DtoCatAssignElement(l,e2);
-        DtoAssign(l, slice);
+        DtoAssign(loc, l, slice);
     }
     else if (e1type == e2type) {
         DSliceValue* slice = DtoCatAssignArray(l,e2);
-        DtoAssign(l, slice);
+        DtoAssign(loc, l, slice);
     }
     else
         assert(0 && "only one element at a time right now");
@@ -2481,7 +2481,7 @@
         DValue* e = expr->toElem(p);
         DImValue* im = e->isIm();
         if (!im || !im->inPlace()) {
-            DtoAssign(vv, e);
+            DtoAssign(loc, vv, e);
         }
     }
 
@@ -2566,7 +2566,7 @@
         DValue* ve = vx->toElem(p);
 
         if (!ve->inPlace())
-            DtoAssign(darrptr, ve);
+            DtoAssign(loc, darrptr, ve);
 
         j++;
     }
@@ -2606,7 +2606,7 @@
     DValue* key = e1->toElem(p);
     DValue* aa = e2->toElem(p);
 
-    return DtoAAIn(type, aa, key);
+    return DtoAAIn(loc, type, aa, key);
 }
 
 DValue* RemoveExp::toElem(IRState* p)
@@ -2617,7 +2617,7 @@
     DValue* aa = e1->toElem(p);
     DValue* key = e2->toElem(p);
 
-    DtoAARemove(aa, key);
+    DtoAARemove(loc, aa, key);
 
     return NULL; // does not produce anything useful
 }
@@ -2652,11 +2652,11 @@
 
         // index
         DValue* key = ekey->toElem(p);
-        DValue* mem = DtoAAIndex(vtype, aa, key);
+        DValue* mem = DtoAAIndex(loc, vtype, aa, key);
 
         // store
         DValue* val = eval->toElem(p);
-        DtoAssign(mem, val);
+        DtoAssign(loc, mem, val);
     }
 
     return aa;