Permalink
Browse files

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'.
  • Loading branch information...
1 parent e7c72b0 commit c6abdcf4a44e8bf65e77da9431af4b94eb76d056 @klickverbot klickverbot committed Sep 27, 2012
Showing with 19 additions and 11 deletions.
  1. +0 −2 dmd2/mtype.h
  2. +2 −2 gen/binops.cpp
  3. +8 −1 gen/llvmhelpers.cpp
  4. +4 −0 gen/llvmhelpers.h
  5. +1 −1 gen/statements.cpp
  6. +2 −3 gen/toir.cpp
  7. +2 −2 gen/typinf.cpp
View
@@ -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();
View
@@ -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");
View
@@ -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() <<
View
@@ -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
////////////////////////////////////////////
View
@@ -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
View
@@ -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");
View
@@ -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);
}

0 comments on commit c6abdcf

Please sign in to comment.