comparison gen/toir.cpp @ 1202:7c7072437a89

Introduce checks to fix #173.
author Christian Kamm <kamm incasoftware de>
date Sun, 12 Apr 2009 14:58:18 +0200
parents c6f39553b702
children 50dc0db06238
comparison
equal deleted inserted replaced
1201:14a30bada44f 1202:7c7072437a89
593 593
594 #undef BIN_ASSIGN 594 #undef BIN_ASSIGN
595 595
596 ////////////////////////////////////////////////////////////////////////////////////////// 596 //////////////////////////////////////////////////////////////////////////////////////////
597 597
598 static void errorOnIllegalArrayOp(Expression* base, Expression* e1, Expression* e2)
599 {
600 Type* t1 = e1->type->toBasetype();
601 Type* t2 = e2->type->toBasetype();
602
603 // valid array ops would have been transformed by optimize
604 if ((t1->ty == Tarray || t1->ty == Tsarray) &&
605 (t2->ty == Tarray || t2->ty == Tsarray)
606 )
607 {
608 error("Array operation %s not recognized", base->toChars());
609 fatal();
610 }
611 }
612
613 //////////////////////////////////////////////////////////////////////////////////////////
614
598 DValue* AddExp::toElem(IRState* p) 615 DValue* AddExp::toElem(IRState* p)
599 { 616 {
600 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars()); 617 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars());
601 LOG_SCOPE; 618 LOG_SCOPE;
602 619
605 622
606 Type* t = type->toBasetype(); 623 Type* t = type->toBasetype();
607 Type* e1type = e1->type->toBasetype(); 624 Type* e1type = e1->type->toBasetype();
608 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; 625 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL;
609 Type* e2type = e2->type->toBasetype(); 626 Type* e2type = e2->type->toBasetype();
627
628 errorOnIllegalArrayOp(this, e1, e2);
610 629
611 if (e1type != e2type) { 630 if (e1type != e2type) {
612 if (e1type->ty == Tpointer) { 631 if (e1type->ty == Tpointer) {
613 Logger::println("add to pointer"); 632 Logger::println("add to pointer");
614 if (DConstValue* cv = r->isConst()) { 633 if (DConstValue* cv = r->isConst()) {
645 664
646 Type* t = type->toBasetype(); 665 Type* t = type->toBasetype();
647 Type* t1 = e1->type->toBasetype(); 666 Type* t1 = e1->type->toBasetype();
648 Type* t2 = e2->type->toBasetype(); 667 Type* t2 = e2->type->toBasetype();
649 668
669 errorOnIllegalArrayOp(this, e1, e2);
670
650 if (t1->ty == Tpointer && t2->ty == Tpointer) { 671 if (t1->ty == Tpointer && t2->ty == Tpointer) {
651 LLValue* lv = l->getRVal(); 672 LLValue* lv = l->getRVal();
652 LLValue* rv = r->getRVal(); 673 LLValue* rv = r->getRVal();
653 if (Logger::enabled()) 674 if (Logger::enabled())
654 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; 675 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n';
680 LOG_SCOPE; 701 LOG_SCOPE;
681 702
682 DValue* l = e1->toElem(p); 703 DValue* l = e1->toElem(p);
683 DValue* r = e2->toElem(p); 704 DValue* r = e2->toElem(p);
684 705
706 errorOnIllegalArrayOp(this, e1, e2);
707
685 if (type->iscomplex()) { 708 if (type->iscomplex()) {
686 return DtoComplexMul(loc, type, l, r); 709 return DtoComplexMul(loc, type, l, r);
687 } 710 }
688 711
689 return DtoBinMul(type, l, r); 712 return DtoBinMul(type, l, r);
697 LOG_SCOPE; 720 LOG_SCOPE;
698 721
699 DValue* l = e1->toElem(p); 722 DValue* l = e1->toElem(p);
700 DValue* r = e2->toElem(p); 723 DValue* r = e2->toElem(p);
701 724
725 errorOnIllegalArrayOp(this, e1, e2);
726
702 if (type->iscomplex()) { 727 if (type->iscomplex()) {
703 return DtoComplexDiv(loc, type, l, r); 728 return DtoComplexDiv(loc, type, l, r);
704 } 729 }
705 730
706 return DtoBinDiv(type, l, r); 731 return DtoBinDiv(type, l, r);
713 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars()); 738 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars());
714 LOG_SCOPE; 739 LOG_SCOPE;
715 740
716 DValue* l = e1->toElem(p); 741 DValue* l = e1->toElem(p);
717 DValue* r = e2->toElem(p); 742 DValue* r = e2->toElem(p);
743
744 errorOnIllegalArrayOp(this, e1, e2);
718 745
719 return DtoBinRem(type, l, r); 746 return DtoBinRem(type, l, r);
720 } 747 }
721 748
722 ////////////////////////////////////////////////////////////////////////////////////////// 749 //////////////////////////////////////////////////////////////////////////////////////////
1875 { \ 1902 { \
1876 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \ 1903 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \
1877 LOG_SCOPE; \ 1904 LOG_SCOPE; \
1878 DValue* u = e1->toElem(p); \ 1905 DValue* u = e1->toElem(p); \
1879 DValue* v = e2->toElem(p); \ 1906 DValue* v = e2->toElem(p); \
1907 errorOnIllegalArrayOp(this, e1, e2); \
1880 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ 1908 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \
1881 return new DImValue(type, x); \ 1909 return new DImValue(type, x); \
1882 } 1910 }
1883 1911
1884 BinBitExp(And,And); 1912 BinBitExp(And,And);