diff --git a/dmd2/mtype.h b/dmd2/mtype.h index a35f9f5cff..3b1cd74068 100644 --- a/dmd2/mtype.h +++ b/dmd2/mtype.h @@ -597,8 +597,6 @@ struct TypePointer : TypeNext MATCH implicitConvTo(Type *to); MATCH constConv(Type *to); int isscalar(); - // LDC: pointers are unsigned - int isunsigned() { return TRUE; }; Expression *defaultInit(Loc loc); int isZeroInit(Loc loc); TypeInfoDeclaration *getTypeInfoDeclaration(); diff --git a/gen/binops.cpp b/gen/binops.cpp index c23707dac8..6829660cba 100644 --- a/gen/binops.cpp +++ b/gen/binops.cpp @@ -74,7 +74,7 @@ DValue* DtoBinDiv(Type* targettype, DValue* lhs, DValue* rhs) LLValue* res; if (t->isfloating()) res = gIR->ir->CreateFDiv(l, r, "tmp"); - else if (!t->isunsigned()) + else if (!isLLVMUnsigned(t)) res = gIR->ir->CreateSDiv(l, r, "tmp"); else res = gIR->ir->CreateUDiv(l, r, "tmp"); @@ -92,7 +92,7 @@ DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs) LLValue* res; if (t->isfloating()) res = gIR->ir->CreateFRem(l, r, "tmp"); - else if (!t->isunsigned()) + else if (!isLLVMUnsigned(t)) res = gIR->ir->CreateSRem(l, r, "tmp"); else res = gIR->ir->CreateURem(l, r, "tmp"); diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 73e84d29db..e959338555 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -593,7 +593,7 @@ DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to) if (fromsz < tosz || from->ty == Tbool) { if (Logger::enabled()) Logger::cout() << "cast to: " << *tolltype << '\n'; - if (from->isunsigned() || from->ty == Tbool) { + if (isLLVMUnsigned(from) || from->ty == Tbool) { rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb()); } else { rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb()); @@ -1844,6 +1844,13 @@ bool isSpecialRefVar(VarDeclaration* vd) ////////////////////////////////////////////////////////////////////////////////////////// +bool isLLVMUnsigned(Type* t) +{ + return t->isunsigned() || t->ty == Tpointer; +} + +////////////////////////////////////////////////////////////////////////////////////////// + void printLabelName(std::ostream& target, const char* func_mangle, const char* label_name) { target << gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix() << diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 4a11dcd7ff..4cecf41e09 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -167,6 +167,10 @@ void callPostblit(Loc &loc, Expression *exp, LLValue *val); /// implicit __result variable for ref-return functions with out contracts. bool isSpecialRefVar(VarDeclaration* vd); +/// Returns whether the type is unsigned in LLVM terms, which also includes +/// pointers. +bool isLLVMUnsigned(Type* t); + //////////////////////////////////////////// // gen/tocall.cpp stuff below //////////////////////////////////////////// diff --git a/gen/statements.cpp b/gen/statements.cpp index c9212c740a..2d1072a424 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -1317,7 +1317,7 @@ void ForeachRangeStatement::toIR(IRState* p) lower = DtoLoad(keyval); assert(lower->getType() == upper->getType()); llvm::ICmpInst::Predicate cmpop; - if (key->type->isunsigned()) + if (isLLVMUnsigned(key->type)) { cmpop = (op == TOKforeach) ? llvm::ICmpInst::ICMP_ULT diff --git a/gen/toir.cpp b/gen/toir.cpp index d4b9839f1b..7b72dde2be 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1714,8 +1714,7 @@ DValue* CmpExp::toElem(IRState* p) { llvm::ICmpInst::Predicate cmpop; bool skip = false; - // pointers don't report as being unsigned - bool uns = (t->isunsigned() || t->ty == Tpointer); + bool uns = isLLVMUnsigned(t); switch(op) { case TOKlt: @@ -2351,7 +2350,7 @@ DValue* ShrExp::toElem(IRState* p) DValue* u = e1->toElem(p); DValue* v = e2->toElem(p); LLValue* x; - if (e1->type->isunsigned()) + if (isLLVMUnsigned(e1->type)) x = p->ir->CreateLShr(u->getRVal(), v->getRVal(), "tmp"); else x = p->ir->CreateAShr(u->getRVal(), v->getRVal(), "tmp"); diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 53d125859b..ee68b86a26 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -462,9 +462,9 @@ void TypeInfoEnumDeclaration::llvmDefine() { LLType* memty = DtoType(sd->memtype); #if DMDV2 - LLConstant* C = LLConstantInt::get(memty, sd->defaultval->toInteger(), !sd->memtype->isunsigned()); + LLConstant* C = LLConstantInt::get(memty, sd->defaultval->toInteger(), !isLLVMUnsigned(sd->memtype)); #else - LLConstant* C = LLConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); + LLConstant* C = LLConstantInt::get(memty, sd->defaultval, !isLLVMUnsigned(sd->memtype)); #endif b.push_void_array(C, sd->memtype, sd); }