Mercurial > projects > ldc
comparison gen/toir.cpp @ 1166:c6f39553b702
Clean up some suspicious code.
There's no guarantee a constant of integer type is a ConstantInt, so it's not
safe to just cast<> these to ConstantInt. (It could be a constant expression,
for example)
The code is shorter this way too :).
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 29 Mar 2009 03:27:04 +0200 |
parents | f528e55fb32f |
children | 7c7072437a89 83d3b25c2213 |
comparison
equal
deleted
inserted
replaced
1165:226c07c71967 | 1166:c6f39553b702 |
---|---|
609 Type* e2type = e2->type->toBasetype(); | 609 Type* e2type = e2->type->toBasetype(); |
610 | 610 |
611 if (e1type != e2type) { | 611 if (e1type != e2type) { |
612 if (e1type->ty == Tpointer) { | 612 if (e1type->ty == Tpointer) { |
613 Logger::println("add to pointer"); | 613 Logger::println("add to pointer"); |
614 if (r->isConst()) { | 614 if (DConstValue* cv = r->isConst()) { |
615 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); | 615 if (cv->c->isNullValue()) { |
616 if (cofs->isZero()) { | |
617 Logger::println("is zero"); | 616 Logger::println("is zero"); |
618 return new DImValue(type, l->getRVal()); | 617 return new DImValue(type, l->getRVal()); |
619 } | 618 } |
620 } | 619 } |
621 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); | 620 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); |