mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
[svn r385] Fix lvalue cast problems with -= and friends.
Fix complex DtoBoolean.
This commit is contained in:
@@ -757,7 +757,8 @@ static LLValue* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
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");
|
||||
|
||||
|
||||
@@ -320,10 +320,14 @@ LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs)
|
||||
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");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -151,7 +151,6 @@ void IfStatement::toIR(IRState* p)
|
||||
|
||||
DValue* cond_e = condition->toElem(p);
|
||||
LLValue* cond_val = cond_e->getRVal();
|
||||
delete cond_e;
|
||||
|
||||
llvm::BasicBlock* oldend = gIR->scopeend();
|
||||
|
||||
@@ -161,7 +160,7 @@ void IfStatement::toIR(IRState* p)
|
||||
|
||||
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 @@ void WhileStatement::toIR(IRState* p)
|
||||
|
||||
// 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 @@ void DoStatement::toIR(IRState* p)
|
||||
|
||||
// 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 @@ void ForStatement::toIR(IRState* p)
|
||||
|
||||
// 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
|
||||
|
||||
25
gen/toir.cpp
25
gen/toir.cpp
@@ -665,8 +665,6 @@ DValue* AddAssignExp::toElem(IRState* p)
|
||||
}
|
||||
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 @@ DValue* MinAssignExp::toElem(IRState* p)
|
||||
}
|
||||
DtoAssign(l, res);
|
||||
|
||||
return l;
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -778,7 +776,7 @@ DValue* MulAssignExp::toElem(IRState* p)
|
||||
}
|
||||
DtoAssign(l, res);
|
||||
|
||||
return l;
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -817,7 +815,7 @@ DValue* DivAssignExp::toElem(IRState* p)
|
||||
}
|
||||
DtoAssign(l, res);
|
||||
|
||||
return l;
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -846,7 +844,7 @@ DValue* ModAssignExp::toElem(IRState* p)
|
||||
DValue* res = DtoBinRem(l, r);
|
||||
DtoAssign(l, res);
|
||||
|
||||
return l;
|
||||
return res;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1967,8 +1965,7 @@ DValue* AssertExp::toElem(IRState* p)
|
||||
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* NotExp::toElem(IRState* p)
|
||||
|
||||
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 @@ DValue* AndAndExp::toElem(IRState* p)
|
||||
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 @@ DValue* OrOrExp::toElem(IRState* p)
|
||||
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 @@ DValue* CondExp::toElem(IRState* p)
|
||||
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);
|
||||
|
||||
@@ -326,10 +326,13 @@ LLValue* DtoPointedType(LLValue* ptr, LLValue* val)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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 @@ LLValue* DtoBoolean(LLValue* val)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ unsigned DtoCallingConv(LINK l);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user