changeset 364:8014dbd24605 trunk

[svn r385] Fix lvalue cast problems with -= and friends. Fix complex DtoBoolean.
author ChristianK
date Mon, 14 Jul 2008 22:48:03 +0200
parents 4d7495038ae8
children bfb9d28f045a
files gen/arrays.cpp gen/complex.cpp gen/statements.cpp gen/toir.cpp gen/tollvm.cpp gen/tollvm.h
diffstat 6 files changed, 36 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/gen/arrays.cpp	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/arrays.cpp	Mon Jul 14 22:48:03 2008 +0200
@@ -757,7 +757,8 @@
 //////////////////////////////////////////////////////////////////////////////////////////
 LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r)
 {
-    LLValue* res = DtoBoolean(DtoArrayEqCmp_impl("_adEq", l, r, true));
+    LLValue* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
+    res = new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, res, DtoConstInt(0), "tmp", gIR->scopebb());
     if (op == TOKnotequal)
         res = gIR->ir->CreateNot(res, "tmp");
 
--- a/gen/complex.cpp	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/complex.cpp	Mon Jul 14 22:48:03 2008 +0200
@@ -320,10 +320,14 @@
     else
         cmpop = llvm::FCmpInst::FCMP_UNE;
 
-    // (l.re==r.re && l.im==r.im)
+    // (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im)
     LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb());
     LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb());
-    return gIR->ir->CreateAnd(b1,b2,"tmp");
+
+    if (op == TOKequal)
+        return gIR->ir->CreateAnd(b1,b2,"tmp");
+    else
+        return gIR->ir->CreateOr(b1,b2,"tmp");
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/statements.cpp	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/statements.cpp	Mon Jul 14 22:48:03 2008 +0200
@@ -151,7 +151,6 @@
 
     DValue* cond_e = condition->toElem(p);
     LLValue* cond_val = cond_e->getRVal();
-    delete cond_e;
 
     llvm::BasicBlock* oldend = gIR->scopeend();
 
@@ -161,7 +160,7 @@
 
     if (cond_val->getType() != LLType::Int1Ty) {
         Logger::cout() << "if conditional: " << *cond_val << '\n';
-        cond_val = DtoBoolean(cond_val);
+        cond_val = DtoBoolean(cond_e);
     }
     LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb());
 
@@ -249,7 +248,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e->getRVal());
+    LLValue* cond_val = DtoBoolean(cond_e);
     delete cond_e;
 
     // conditional branch
@@ -300,7 +299,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e->getRVal());
+    LLValue* cond_val = DtoBoolean(cond_e);
     delete cond_e;
 
     // conditional branch
@@ -342,7 +341,7 @@
 
     // create the condition
     DValue* cond_e = condition->toElem(p);
-    LLValue* cond_val = DtoBoolean(cond_e->getRVal());
+    LLValue* cond_val = DtoBoolean(cond_e);
     delete cond_e;
 
     // conditional branch
--- a/gen/toir.cpp	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/toir.cpp	Mon Jul 14 22:48:03 2008 +0200
@@ -665,8 +665,6 @@
     }
     DtoAssign(l, res);
 
-    // might need to return l here if used as an lvalue
-    // but when can this ever happen?
     return res;
 }
 
@@ -739,7 +737,7 @@
     }
     DtoAssign(l, res);
 
-    return l;
+    return res;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -778,7 +776,7 @@
     }
     DtoAssign(l, res);
 
-    return l;
+    return res;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -817,7 +815,7 @@
     }
     DtoAssign(l, res);
 
-    return l;
+    return res;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -846,7 +844,7 @@
     DValue* res = DtoBinRem(l, r);
     DtoAssign(l, res);
 
-    return l;
+    return res;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -1967,8 +1965,7 @@
     llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend);
 
     // test condition
-    LLValue* condval = cond->getRVal();
-    condval = DtoBoolean(condval);
+    LLValue* condval = DtoBoolean(cond);
 
     // branch
     llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb());
@@ -1997,7 +1994,7 @@
 
     DValue* u = e1->toElem(p);
 
-    LLValue* b = DtoBoolean(u->getRVal());
+    LLValue* b = DtoBoolean(u);
 
     LLConstant* zero = llvm::ConstantInt::get(LLType::Int1Ty, 0, true);
     b = p->ir->CreateICmpEQ(b,zero);
@@ -2023,14 +2020,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->getRVal());
+    LLValue* ubool = DtoBoolean(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->getRVal());
+    LLValue* vbool = DtoBoolean(v);
     LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb());
     DtoStore(uandvbool,resval);
     llvm::BranchInst::Create(andandend,p->scopebb());
@@ -2059,14 +2056,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->getRVal());
+    LLValue* ubool = DtoBoolean(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->getRVal());
+    LLValue* vbool = DtoBoolean(v);
     DtoStore(vbool,resval);
     llvm::BranchInst::Create(ororend,p->scopebb());
 
@@ -2321,7 +2318,7 @@
     llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend);
 
     DValue* c = econd->toElem(p);
-    LLValue* cond_val = DtoBoolean(c->getRVal());
+    LLValue* cond_val = DtoBoolean(c);
     llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb());
 
     p->scope() = IRScope(condtrue, condfalse);
--- a/gen/tollvm.cpp	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/tollvm.cpp	Mon Jul 14 22:48:03 2008 +0200
@@ -326,10 +326,13 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-LLValue* DtoBoolean(LLValue* val)
+LLValue* DtoBoolean(DValue* dval)
 {
+    Type* dtype = dval->getType()->toBasetype();
+    LLValue* val = dval->getRVal();
     const LLType* t = val->getType();
-    if (t->isInteger())
+
+    if (dtype->isintegral())
     {
         if (t == LLType::Int1Ty)
             return val;
@@ -338,16 +341,20 @@
             return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
         }
     }
-    else if (t->isFloatingPoint())
+    else if (dtype->iscomplex())
+    {
+        return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0))));
+    }
+    else if (dtype->isfloating())
     {
         LLValue* zero = llvm::Constant::getNullValue(t);
         return new llvm::FCmpInst(llvm::FCmpInst::FCMP_ONE, val, zero, "tmp", gIR->scopebb());
     }
-    else if (isaPointer(t)) {
+    else if (dtype->ty == Tpointer) {
         LLValue* zero = llvm::Constant::getNullValue(t);
         return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
     }
-    std::cout << "unsupported -> bool : " << *t << '\n';
+    std::cout << "unsupported -> bool : " << dtype->toChars() << " " << *t << '\n';
     assert(0);
     return 0;
 }
--- a/gen/tollvm.h	Mon Jul 14 21:49:54 2008 +0200
+++ b/gen/tollvm.h	Mon Jul 14 22:48:03 2008 +0200
@@ -41,7 +41,7 @@
 LLValue* DtoPointedType(LLValue* ptr, LLValue* val);
 
 // casts any value to a boolean
-LLValue* DtoBoolean(LLValue* val);
+LLValue* DtoBoolean(DValue* dval);
 
 // some types
 const LLType* DtoSize_t();