From edc4a5f0032d4abf164efbd4ada2f49a1fc7b796 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Thu, 15 Dec 2011 13:31:39 +0400 Subject: [PATCH] DMD Issue 5416 - null should have a type of its own --- dmd/mtype.h | 1 + gen/statements.cpp | 2 ++ gen/toir.cpp | 4 ++-- gen/tollvm.cpp | 1 + gen/typinf.cpp | 6 +++++- ir/irtype.cpp | 9 ++++++++- ir/irtype.h | 2 ++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dmd/mtype.h b/dmd/mtype.h index 61ecd3d0..e7e98b16 100644 --- a/dmd/mtype.h +++ b/dmd/mtype.h @@ -106,6 +106,7 @@ enum TY Ttuple, Tslice, Treturn, + Tnull, TMAX }; diff --git a/gen/statements.cpp b/gen/statements.cpp index af0e24f0..47efee98 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -96,6 +96,8 @@ void ReturnStatement::toIR(IRState* p) if (!exp && (p->topfunc() == p->mainFunc)) { v = LLConstant::getNullValue(p->mainFunc->getReturnType()); } else { + if (exp->op == TOKnull) + exp->type = p->func()->type->next; #if DMDV2 DValue* dval = 0; // call postblit if necessary diff --git a/gen/toir.cpp b/gen/toir.cpp index 08153234..bcc51f50 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1551,7 +1551,7 @@ DValue* CmpExp::toElem(IRState* p) LLValue* eval = 0; - if (t->isintegral() || t->ty == Tpointer) + if (t->isintegral() || t->ty == Tpointer || t->ty == Tnull) { llvm::ICmpInst::Predicate cmpop; bool skip = false; @@ -1677,7 +1677,7 @@ DValue* EqualExp::toElem(IRState* p) // the Tclass catches interface comparisons, regular // class equality should be rewritten as a.opEquals(b) by this time - if (t->isintegral() || t->ty == Tpointer || t->ty == Tclass) + if (t->isintegral() || t->ty == Tpointer || t->ty == Tclass || t->ty == Tnull) { Logger::println("integral or pointer or interface"); llvm::ICmpInst::Predicate cmpop; diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 14274853..37f462b9 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -95,6 +95,7 @@ LLType* DtoType(Type* t) } // pointers + case Tnull: case Tpointer: { t->irtype = new IrTypePointer(t); diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 0e8e71ac..3933c656 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -380,7 +380,11 @@ void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) void TypeInfoDeclaration::llvmDefine() { - assert(0 && "cannot generate generic typeinfo"); + Logger::println("TypeInfoDeclaration::llvmDefine() %s", toChars()); + LOG_SCOPE; + + RTTIBuilder b(Type::typeinfo); + b.finalize(ir.irGlobal); } /* ========================================================================= */ diff --git a/ir/irtype.cpp b/ir/irtype.cpp index 92833314..266bcc34 100644 --- a/ir/irtype.cpp +++ b/ir/irtype.cpp @@ -137,7 +137,7 @@ llvm::Type * IrTypeBasic::basic2llvm(Type* t) ////////////////////////////////////////////////////////////////////////////// IrTypePointer::IrTypePointer(Type * dt) -: IrType(dt, pointer2llvm(dt)) +: IrType(dt, dt->ty == Tnull ? null2llvm(dt) : pointer2llvm(dt)) { } @@ -160,6 +160,13 @@ llvm::Type * IrTypePointer::pointer2llvm(Type * dt) return llvm::PointerType::get(elemType, 0); } +llvm::Type* IrTypePointer::null2llvm(Type* dt) +{ + assert(dt->ty == Tnull && "not null type"); + LLType* elemType = llvm::Type::getInt8Ty(llvm::getGlobalContext()); + return llvm::PointerType::get(elemType, 0); +} + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// diff --git a/ir/irtype.h b/ir/irtype.h index c90ffcc8..d0fc4e6a 100644 --- a/ir/irtype.h +++ b/ir/irtype.h @@ -105,6 +105,8 @@ public: protected: /// llvm::Type* pointer2llvm(Type* t); + /// + llvm::Type* null2llvm(Type* t); }; //////////////////////////////////////////////////////////////////////////////