Skip to content

Commit 3b31aa1

Browse files
committed
[ensure no more DConstValues for function ptrs and delegates]
1 parent 5406ef3 commit 3b31aa1

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

gen/dvalue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ DImValue::DImValue(Type *t, llvm::Value *v) : DRValue(t, v) {
8080

8181
DConstValue::DConstValue(Type *t, LLConstant *con) : DRValue(t, con) {
8282
assert(con->getType() == DtoType(t));
83+
assert(!t->toBasetype()->isFunction_Delegate_PtrToFunction());
8384
}
8485

8586
////////////////////////////////////////////////////////////////////////////////

gen/llvmhelpers.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,17 @@ DValue *DtoNullValue(Type *type, Loc loc) {
467467
LLConstant::getNullValue(basefp));
468468
return new DImValue(type, res);
469469
}
470-
// integer, floating, pointer, assoc array, delegate and class have no special
470+
// function pointers and delegates
471+
if (basetype->isFunction_Delegate_PtrToFunction()) {
472+
return new DFuncValue(
473+
type, nullptr, getNullPtr(gDataLayout->getProgramAddressSpace()),
474+
basety == TY::Tdelegate ? getNullPtr() : nullptr);
475+
}
476+
// integer, floating, pointer, assoc array, and class have no special
471477
// representation
472478
if (basetype->isintegral() || basetype->isfloating() ||
473479
basety == TY::Tpointer || basety == TY::Tnull || basety == TY::Tclass ||
474-
basety == TY::Tdelegate || basety == TY::Taarray) {
480+
basety == TY::Taarray) {
475481
return new DNullValue(type, LLConstant::getNullValue(lltype));
476482
}
477483
// dynamic array

gen/toir.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ class ToElemVisitor : public Visitor {
381381
IF_LOG Logger::print("NullExp::toElem(type=%s): %s\n", e->type->toChars(),
382382
e->toChars());
383383
LOG_SCOPE;
384-
LLConstant *c = toConstElem(e, p);
385-
result = new DNullValue(e->type, c);
384+
result = DtoNullValue(e->type, e->loc);
386385
}
387386

388387
//////////////////////////////////////////////////////////////////////////////

gen/tollvm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace) {
697697
return LLPointerType::get(gIR->context(), addressSpace);
698698
}
699699

700-
llvm::ConstantPointerNull *getNullPtr() {
701-
return llvm::ConstantPointerNull::get(getOpaquePtrType());
700+
llvm::ConstantPointerNull *getNullPtr(unsigned addressSpace) {
701+
return llvm::ConstantPointerNull::get(getOpaquePtrType(addressSpace));
702702
}
703703

704704
LLConstant *getNullValue(LLType *t) { return LLConstant::getNullValue(t); }

gen/tollvm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ LLGlobalVariable *isaGlobalVar(LLValue *v);
149149
// llvm::T::get(...) wrappers
150150
LLType *getI8Type();
151151
LLPointerType *getOpaquePtrType(unsigned addressSpace = 0);
152-
llvm::ConstantPointerNull *getNullPtr();
152+
llvm::ConstantPointerNull *getNullPtr(unsigned addressSpace = 0);
153153
LLConstant *getNullValue(LLType *t);
154154

155155
// type sizes

0 commit comments

Comments
 (0)