diff --git a/gen/dvalue.cpp b/gen/dvalue.cpp index 86d3b93580..f72d36bc02 100644 --- a/gen/dvalue.cpp +++ b/gen/dvalue.cpp @@ -80,6 +80,7 @@ DImValue::DImValue(Type *t, llvm::Value *v) : DRValue(t, v) { DConstValue::DConstValue(Type *t, LLConstant *con) : DRValue(t, con) { assert(con->getType() == DtoType(t)); + assert(!t->toBasetype()->isFunction_Delegate_PtrToFunction()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 73ad909ffb..b34e16a41f 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -467,11 +467,17 @@ DValue *DtoNullValue(Type *type, Loc loc) { LLConstant::getNullValue(basefp)); return new DImValue(type, res); } - // integer, floating, pointer, assoc array, delegate and class have no special + // function pointers and delegates + if (basetype->isFunction_Delegate_PtrToFunction()) { + return new DFuncValue( + type, nullptr, getNullPtr(gDataLayout->getProgramAddressSpace()), + basety == TY::Tdelegate ? getNullPtr() : nullptr); + } + // integer, floating, pointer, assoc array, and class have no special // representation if (basetype->isintegral() || basetype->isfloating() || basety == TY::Tpointer || basety == TY::Tnull || basety == TY::Tclass || - basety == TY::Tdelegate || basety == TY::Taarray) { + basety == TY::Taarray) { return new DNullValue(type, LLConstant::getNullValue(lltype)); } // dynamic array diff --git a/gen/toir.cpp b/gen/toir.cpp index d6cb5784c3..65a4300468 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -381,8 +381,7 @@ class ToElemVisitor : public Visitor { IF_LOG Logger::print("NullExp::toElem(type=%s): %s\n", e->type->toChars(), e->toChars()); LOG_SCOPE; - LLConstant *c = toConstElem(e, p); - result = new DNullValue(e->type, c); + result = DtoNullValue(e->type, e->loc); } ////////////////////////////////////////////////////////////////////////////// diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 36af312736..a9b9ab2051 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -697,8 +697,8 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace) { return LLPointerType::get(gIR->context(), addressSpace); } -llvm::ConstantPointerNull *getNullPtr() { - return llvm::ConstantPointerNull::get(getOpaquePtrType()); +llvm::ConstantPointerNull *getNullPtr(unsigned addressSpace) { + return llvm::ConstantPointerNull::get(getOpaquePtrType(addressSpace)); } LLConstant *getNullValue(LLType *t) { return LLConstant::getNullValue(t); } diff --git a/gen/tollvm.h b/gen/tollvm.h index f8e195d2ac..757fa8e281 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -149,7 +149,7 @@ LLGlobalVariable *isaGlobalVar(LLValue *v); // llvm::T::get(...) wrappers LLType *getI8Type(); LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); -llvm::ConstantPointerNull *getNullPtr(); +llvm::ConstantPointerNull *getNullPtr(unsigned addressSpace = 0); LLConstant *getNullValue(LLType *t); // type sizes