# HG changeset patch # User Christian Kamm # Date 1239541098 -7200 # Node ID 7c7072437a89135543a01b3b15f6bd141338f474 # Parent 14a30bada44fb5abf316ce2e875b3d3315e0dc66 Introduce checks to fix #173. diff -r 14a30bada44f -r 7c7072437a89 gen/toir.cpp --- a/gen/toir.cpp Sun Apr 12 13:50:18 2009 +0200 +++ b/gen/toir.cpp Sun Apr 12 14:58:18 2009 +0200 @@ -595,6 +595,23 @@ ////////////////////////////////////////////////////////////////////////////////////////// +static void errorOnIllegalArrayOp(Expression* base, Expression* e1, Expression* e2) +{ + Type* t1 = e1->type->toBasetype(); + Type* t2 = e2->type->toBasetype(); + + // valid array ops would have been transformed by optimize + if ((t1->ty == Tarray || t1->ty == Tsarray) && + (t2->ty == Tarray || t2->ty == Tsarray) + ) + { + error("Array operation %s not recognized", base->toChars()); + fatal(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// + DValue* AddExp::toElem(IRState* p) { Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars()); @@ -608,6 +625,8 @@ Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; Type* e2type = e2->type->toBasetype(); + errorOnIllegalArrayOp(this, e1, e2); + if (e1type != e2type) { if (e1type->ty == Tpointer) { Logger::println("add to pointer"); @@ -647,6 +666,8 @@ Type* t1 = e1->type->toBasetype(); Type* t2 = e2->type->toBasetype(); + errorOnIllegalArrayOp(this, e1, e2); + if (t1->ty == Tpointer && t2->ty == Tpointer) { LLValue* lv = l->getRVal(); LLValue* rv = r->getRVal(); @@ -682,6 +703,8 @@ DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); + errorOnIllegalArrayOp(this, e1, e2); + if (type->iscomplex()) { return DtoComplexMul(loc, type, l, r); } @@ -699,6 +722,8 @@ DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); + errorOnIllegalArrayOp(this, e1, e2); + if (type->iscomplex()) { return DtoComplexDiv(loc, type, l, r); } @@ -716,6 +741,8 @@ DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); + errorOnIllegalArrayOp(this, e1, e2); + return DtoBinRem(type, l, r); } @@ -1877,6 +1904,7 @@ LOG_SCOPE; \ DValue* u = e1->toElem(p); \ DValue* v = e2->toElem(p); \ + errorOnIllegalArrayOp(this, e1, e2); \ LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ return new DImValue(type, x); \ }