mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00
Don't set TypePointer::isunsigned to true in the frontend.
The previous solution was problematic because the change was language- visble via the isUnsigned trait. Now, pointers are simply explicitly checked for in the relevant places. (Note that there might be cases in the diff where a direct isunsigned() call would have been appropriate – I only checked for instances where the type clearly cannot be a pointer, but chose to go the safe route in replicating existing behavior otherwise). Fixes DMD testcase 'traits'.
This commit is contained in:
parent
e7c72b072b
commit
c6abdcf4a4
7 changed files with 19 additions and 11 deletions
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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() <<
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue