Skip to content

Commit

Permalink
[ensure no more DConstValues for function ptrs and delegates]
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Sep 29, 2024
1 parent 79d56f7 commit 9aa35dc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions gen/dvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 8 additions & 2 deletions gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions gen/tollvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 1 addition & 1 deletion gen/tollvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9aa35dc

Please sign in to comment.