Replace getVoidPtrType()

This commit is contained in:
Martin Kinkelin 2024-07-18 23:08:43 +02:00
parent f2fe3f51e5
commit 0c1623c1a0
19 changed files with 64 additions and 77 deletions

View file

@ -109,14 +109,14 @@ void emitLLVMUsedArray(IRState &irs) {
return; return;
} }
auto *i8PtrType = getVoidPtrType(irs.context()); auto ptrType = LLPointerType::get(irs.context(), 0);
// Convert all elements to i8* (the expected type for llvm.used) // Convert all elements to i8* (the expected type for llvm.used)
for (auto &elem : irs.usedArray) { for (auto &elem : irs.usedArray) {
elem = llvm::ConstantExpr::getBitCast(elem, i8PtrType); elem = llvm::ConstantExpr::getBitCast(elem, ptrType);
} }
auto *arrayType = llvm::ArrayType::get(i8PtrType, irs.usedArray.size()); auto *arrayType = llvm::ArrayType::get(ptrType, irs.usedArray.size());
auto *llvmUsed = new llvm::GlobalVariable( auto *llvmUsed = new llvm::GlobalVariable(
irs.module, arrayType, false, llvm::GlobalValue::AppendingLinkage, irs.module, arrayType, false, llvm::GlobalValue::AppendingLinkage,
llvm::ConstantArray::get(arrayType, irs.usedArray), "llvm.used"); llvm::ConstantArray::get(arrayType, irs.usedArray), "llvm.used");

View file

@ -336,13 +336,13 @@ void X86_64TargetABI::rewriteVarargs(IrFuncTy &fty,
LLType *X86_64TargetABI::getValistType() { LLType *X86_64TargetABI::getValistType() {
LLType *uintType = LLType::getInt32Ty(gIR->context()); LLType *uintType = LLType::getInt32Ty(gIR->context());
LLType *voidPointerType = getVoidPtrType(); LLType *pointerType = getOpaquePtrType();
std::vector<LLType *> parts; // struct __va_list_tag { std::vector<LLType *> parts; // struct __va_list_tag {
parts.push_back(uintType); // uint gp_offset; parts.push_back(uintType); // uint gp_offset;
parts.push_back(uintType); // uint fp_offset; parts.push_back(uintType); // uint fp_offset;
parts.push_back(voidPointerType); // void* overflow_arg_area; parts.push_back(pointerType); // void* overflow_arg_area;
parts.push_back(voidPointerType); // void* reg_save_area; } parts.push_back(pointerType); // void* reg_save_area; }
return LLStructType::get(gIR->context(), parts); return LLStructType::get(gIR->context(), parts);
} }

View file

@ -303,19 +303,17 @@ DValue *DtoCastClass(const Loc &loc, DValue *val, Type *_to) {
// it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it // it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it
// should be pretty cheap and perfectly safe even if the original was // should be pretty cheap and perfectly safe even if the original was
// null. // null.
LLValue *isNull = gIR->ir->CreateICmpEQ( const auto nullPtr = getNullPtr();
orig, LLConstant::getNullValue(orig->getType()), ".nullcheck"); LLValue *isNull = gIR->ir->CreateICmpEQ(orig, nullPtr, ".nullcheck");
v = gIR->ir->CreateSelect( v = gIR->ir->CreateSelect(isNull, nullPtr, v, ".interface");
isNull, LLConstant::getNullValue(getVoidPtrType()), v, ".interface");
// return r-value // return r-value
return new DImValue(_to, v); return new DImValue(_to, v);
} }
if (fc->sym->classKind == ClassKind::cpp) { if (fc->sym->classKind == ClassKind::cpp) {
Logger::println("C++ class/interface cast"); Logger::println("C++ class/interface cast");
LLValue *v = tc->sym->classKind == ClassKind::cpp LLValue *v =
? DtoRVal(val) tc->sym->classKind == ClassKind::cpp ? DtoRVal(val) : getNullPtr();
: LLConstant::getNullValue(getVoidPtrType());
return new DImValue(_to, v); return new DImValue(_to, v);
} }

View file

@ -1570,9 +1570,9 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) {
if (tb->ty != TY::Tstruct) { if (tb->ty != TY::Tstruct) {
assert(tb->ty == TY::Tarray && tb->nextOf()->ty == TY::Tvoid); assert(tb->ty == TY::Tarray && tb->nextOf()->ty == TY::Tvoid);
const auto size = DtoConstSize_t(ad->structsize); const auto size = DtoConstSize_t(ad->structsize);
llvm::Constant *ptr = sd && sd->zeroInit() LLConstant *ptr = sd && sd->zeroInit()
? getNullValue(getVoidPtrType()) ? static_cast<LLConstant *>(getNullPtr())
: getIrAggr(ad)->getInitSymbol(); : getIrAggr(ad)->getInitSymbol();
return new DSliceValue(type, size, ptr); return new DSliceValue(type, size, ptr);
} }

View file

@ -173,7 +173,8 @@ llvm::Constant *buildImportedModules(Module *m, size_t &count) {
if (importInits.empty()) if (importInits.empty())
return nullptr; return nullptr;
const auto type = llvm::ArrayType::get(getVoidPtrType(), importInits.size()); const auto type =
llvm::ArrayType::get(getOpaquePtrType(), importInits.size());
return LLConstantArray::get(type, importInits); return LLConstantArray::get(type, importInits);
} }
@ -207,7 +208,8 @@ llvm::Constant *buildLocalClasses(Module *m, size_t &count) {
if (classInfoRefs.empty()) if (classInfoRefs.empty())
return nullptr; return nullptr;
const auto type = llvm::ArrayType::get(getVoidPtrType(), classInfoRefs.size()); const auto type =
llvm::ArrayType::get(getOpaquePtrType(), classInfoRefs.size());
return LLConstantArray::get(type, classInfoRefs); return LLConstantArray::get(type, classInfoRefs);
} }
} }

View file

@ -136,8 +136,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
// provide the default initializer // provide the default initializer
LLStructType *modulerefTy = DtoModuleReferenceType(); LLStructType *modulerefTy = DtoModuleReferenceType();
LLConstant *mrefvalues[] = {LLConstant::getNullValue(getVoidPtrType()), LLConstant *mrefvalues[] = {getNullPtr(), moduleinfo};
moduleinfo};
LLConstant *thismrefinit = LLConstantStruct::get( LLConstant *thismrefinit = LLConstantStruct::get(
modulerefTy, llvm::ArrayRef<LLConstant *>(mrefvalues)); modulerefTy, llvm::ArrayRef<LLConstant *>(mrefvalues));
@ -149,10 +148,10 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
// make sure _Dmodule_ref is declared // make sure _Dmodule_ref is declared
const auto mrefIRMangle = getIRMangledVarName("_Dmodule_ref", LINK::c); const auto mrefIRMangle = getIRMangledVarName("_Dmodule_ref", LINK::c);
LLConstant *mref = gIR->module.getNamedGlobal(mrefIRMangle); LLConstant *mref = gIR->module.getNamedGlobal(mrefIRMangle);
LLType *modulerefPtrTy = getVoidPtrType(); LLType *ptrTy = getOpaquePtrType();
if (!mref) { if (!mref) {
mref = mref =
declareGlobal(Loc(), gIR->module, modulerefPtrTy, mrefIRMangle, false, declareGlobal(Loc(), gIR->module, ptrTy, mrefIRMangle, false,
false, global.params.dllimport != DLLImport::none); false, global.params.dllimport != DLLImport::none);
} }
@ -166,7 +165,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
gIR->DBuilder.EmitModuleCTor(ctor, fname.c_str()); gIR->DBuilder.EmitModuleCTor(ctor, fname.c_str());
// get current beginning // get current beginning
LLValue *curbeg = builder.CreateLoad(modulerefPtrTy, mref, "current"); LLValue *curbeg = builder.CreateLoad(ptrTy, mref, "current");
// put current beginning as the next of this one // put current beginning as the next of this one
LLValue *gep = builder.CreateStructGEP( LLValue *gep = builder.CreateStructGEP(

View file

@ -163,7 +163,7 @@ llvm::StructType *getTypeDescriptorType(IRState &irs,
llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) {
if (cd->isCPPclass()) { if (cd->isCPPclass()) {
const char *name = target.cpp.typeInfoMangle(cd); const char *name = target.cpp.typeInfoMangle(cd);
return declareGlobal(cd->loc, irs.module, getVoidPtrType(), name, return declareGlobal(cd->loc, irs.module, getOpaquePtrType(), name,
/*isConstant*/ true, false, /*isConstant*/ true, false,
/*useDLLImport*/ cd->isExport()); /*useDLLImport*/ cd->isExport());
} }
@ -185,7 +185,7 @@ llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) {
// Declare and initialize the TypeDescriptor. // Declare and initialize the TypeDescriptor.
llvm::Constant *Fields[] = { llvm::Constant *Fields[] = {
classInfoPtr, // VFPtr classInfoPtr, // VFPtr
llvm::ConstantPointerNull::get(getVoidPtrType()), // Runtime data getNullPtr(), // Runtime data
llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)}; llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)};
llvm::StructType *TypeDescriptorType = llvm::StructType *TypeDescriptorType =
getTypeDescriptorType(irs, TypeNameString); getTypeDescriptorType(irs, TypeNameString);

View file

@ -251,7 +251,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) {
if (depth == -1 || (depth == 0 && !symfd->closureVars.empty())) { if (depth == -1 || (depth == 0 && !symfd->closureVars.empty())) {
Logger::println("function does not have context or creates its own " Logger::println("function does not have context or creates its own "
"from scratch, returning null"); "from scratch, returning null");
return llvm::ConstantPointerNull::get(getVoidPtrType()); return getNullPtr();
} }
} }
@ -293,7 +293,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) {
sym->toPrettyChars(), irFunc.decl->toPrettyChars()); sym->toPrettyChars(), irFunc.decl->toPrettyChars());
fatal(); fatal();
} }
return llvm::ConstantPointerNull::get(getVoidPtrType()); return getNullPtr();
} }
// The symbol may need a parent context of the current function. // The symbol may need a parent context of the current function.
@ -525,7 +525,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
} }
if (depth > 1) { if (depth > 1) {
DtoMemCpy(frame, src, DtoConstSize_t((depth - 1) * target.ptrsize), DtoMemCpy(frame, src, DtoConstSize_t((depth - 1) * target.ptrsize),
getABITypeAlign(getVoidPtrType())); getABITypeAlign(getOpaquePtrType()));
} }
// Copy nestArg into framelist; the outer frame is not in the list of // Copy nestArg into framelist; the outer frame is not in the list of
// pointers // pointers

View file

@ -59,7 +59,7 @@ void RTTIBuilder::push(llvm::Constant *C) {
void RTTIBuilder::push_null(Type *T) { push(getNullValue(DtoType(T))); } void RTTIBuilder::push_null(Type *T) { push(getNullValue(DtoType(T))); }
void RTTIBuilder::push_null_vp() { push(getNullValue(getVoidPtrType())); } void RTTIBuilder::push_null_vp() { push(getNullPtr()); }
void RTTIBuilder::push_typeinfo(Type *t) { push(DtoTypeInfoOf(Loc(), t)); } void RTTIBuilder::push_typeinfo(Type *t) { push(DtoTypeInfoOf(Loc(), t)); }
@ -125,7 +125,7 @@ void RTTIBuilder::push_uint(unsigned u) { push(DtoConstUint(u)); }
void RTTIBuilder::push_size(uint64_t s) { push(DtoConstSize_t(s)); } void RTTIBuilder::push_size(uint64_t s) { push(DtoConstSize_t(s)); }
void RTTIBuilder::push_size_as_vp(uint64_t s) { void RTTIBuilder::push_size_as_vp(uint64_t s) {
push(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getVoidPtrType())); push(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getOpaquePtrType()));
} }
void RTTIBuilder::push_funcptr(FuncDeclaration *fd) { void RTTIBuilder::push_funcptr(FuncDeclaration *fd) {

View file

@ -738,7 +738,9 @@ private:
// ... or a delegate context arg // ... or a delegate context arg
LLValue *ctxarg; LLValue *ctxarg;
if (fnval->isLVal()) { if (fnval->isLVal()) {
ctxarg = DtoLoad(getVoidPtrType(), DtoGEP(DtoType(fnval->type), DtoLVal(fnval), 0u, 0), ".ptr"); ctxarg = DtoLoad(getOpaquePtrType(),
DtoGEP(DtoType(fnval->type), DtoLVal(fnval), 0u, 0),
".ptr");
} else { } else {
ctxarg = gIR->ir->CreateExtractValue(DtoRVal(fnval), 0, ".ptr"); ctxarg = gIR->ir->CreateExtractValue(DtoRVal(fnval), 0, ".ptr");
} }
@ -749,7 +751,7 @@ private:
LLValue *contextptr = DtoNestedContext(loc, dfnval->func); LLValue *contextptr = DtoNestedContext(loc, dfnval->func);
args.push_back(contextptr); args.push_back(contextptr);
} else { } else {
args.push_back(llvm::UndefValue::get(getVoidPtrType())); args.push_back(llvm::UndefValue::get(getOpaquePtrType()));
} }
} else { } else {
error(loc, "Context argument required but none given"); error(loc, "Context argument required but none given");

View file

@ -795,7 +795,7 @@ public:
if (canEmitVTableUnchangedAssumption && !dfnval->vtable && if (canEmitVTableUnchangedAssumption && !dfnval->vtable &&
dfnval->vthis && dfnval->func->isVirtual()) { dfnval->vthis && dfnval->func->isVirtual()) {
dfnval->vtable = dfnval->vtable =
DtoLoad(getVoidPtrType(), dfnval->vthis, "saved_vtable"); DtoLoad(getOpaquePtrType(), dfnval->vthis, "saved_vtable");
} }
} }

View file

@ -187,7 +187,7 @@ LLType *DtoType(Type *t) {
// associative arrays // associative arrays
case TY::Taarray: case TY::Taarray:
return getVoidPtrType(); return getOpaquePtrType();
case TY::Tvector: case TY::Tvector:
return IrTypeVector::get(t)->getLLType(); return IrTypeVector::get(t)->getLLType();
@ -438,10 +438,10 @@ void DtoMemCpy(LLType *type, LLValue *dst, LLValue *src, bool withPadding, unsig
LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes) { LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes) {
// int memcmp ( const void * ptr1, const void * ptr2, size_t num ); // int memcmp ( const void * ptr1, const void * ptr2, size_t num );
LLType *VoidPtrTy = getVoidPtrType();
LLFunction *fn = gIR->module.getFunction("memcmp"); LLFunction *fn = gIR->module.getFunction("memcmp");
if (!fn) { if (!fn) {
LLType *Tys[] = {VoidPtrTy, VoidPtrTy, DtoSize_t()}; LLType *ptrTy = getOpaquePtrType();
LLType *Tys[] = {ptrTy, ptrTy, DtoSize_t()};
LLFunctionType *fty = LLFunctionType *fty =
LLFunctionType::get(LLType::getInt32Ty(gIR->context()), Tys, false); LLFunctionType::get(LLType::getInt32Ty(gIR->context()), Tys, false);
fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp",
@ -581,7 +581,7 @@ LLType *stripAddrSpaces(LLType *t)
if (!pt) if (!pt)
return t; return t;
return getVoidPtrType(); return getOpaquePtrType();
} }
LLValue *DtoBitCast(LLValue *v, LLType *t, const llvm::Twine &name) { LLValue *DtoBitCast(LLValue *v, LLType *t, const llvm::Twine &name) {
@ -691,14 +691,6 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace) {
return LLPointerType::get(gIR->context(), addressSpace); return LLPointerType::get(gIR->context(), addressSpace);
} }
LLPointerType *getVoidPtrType() {
return getVoidPtrType(gIR->context());
}
LLPointerType *getVoidPtrType(llvm::LLVMContext &C) {
return LLType::getInt8Ty(C)->getPointerTo();
}
llvm::ConstantPointerNull *getNullPtr() { llvm::ConstantPointerNull *getNullPtr() {
return llvm::ConstantPointerNull::get(getOpaquePtrType()); return llvm::ConstantPointerNull::get(getOpaquePtrType());
} }

View file

@ -149,8 +149,6 @@ LLGlobalVariable *isaGlobalVar(LLValue *v);
// llvm::T::get(...) wrappers // llvm::T::get(...) wrappers
LLType *getI8Type(); LLType *getI8Type();
LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); LLPointerType *getOpaquePtrType(unsigned addressSpace = 0);
LLPointerType *getVoidPtrType();
LLPointerType *getVoidPtrType(llvm::LLVMContext &C);
llvm::ConstantPointerNull *getNullPtr(); llvm::ConstantPointerNull *getNullPtr();
LLConstant *getNullValue(LLType *t); LLConstant *getNullValue(LLType *t);

View file

@ -83,7 +83,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
const auto enterCatchFn = getRuntimeFunction( const auto enterCatchFn = getRuntimeFunction(
c->loc, irs.module, c->loc, irs.module,
isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch"); isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch");
const auto ptr = DtoLoad(getVoidPtrType(), ehPtrSlot); const auto ptr = DtoLoad(getOpaquePtrType(), ehPtrSlot);
const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr); const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr);
// For catches that use the Throwable object, create storage for it. // For catches that use the Throwable object, create storage for it.
@ -171,7 +171,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
if (!ci) { if (!ci) {
const char *name = target.cpp.typeInfoMangle(p.cd); const char *name = target.cpp.typeInfoMangle(p.cd);
auto cpp_ti = declareGlobal( auto cpp_ti = declareGlobal(
p.cd->loc, irs.module, getVoidPtrType(), name, p.cd->loc, irs.module, getOpaquePtrType(), name,
/*isConstant*/ true, false, /*useDLLImport*/ p.cd->isExport()); /*isConstant*/ true, false, /*useDLLImport*/ p.cd->isExport());
const auto cppTypeInfoPtrType = getCppTypeInfoPtrType(); const auto cppTypeInfoPtrType = getCppTypeInfoPtrType();
@ -230,7 +230,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
exnObj = DtoAlloca(ctch->type, "exnObj"); exnObj = DtoAlloca(ctch->type, "exnObj");
} else { } else {
// catch all // catch all
exnObj = LLConstant::getNullValue(getVoidPtrType()); exnObj = getNullPtr();
} }
bool isCPPclass = false; bool isCPPclass = false;
@ -242,8 +242,8 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
clssInfo = getIrAggr(cd)->getClassInfoSymbol(); clssInfo = getIrAggr(cd)->getClassInfoSymbol();
} else { } else {
// catch all // catch all
typeDesc = LLConstant::getNullValue(getVoidPtrType()); typeDesc = getNullPtr();
clssInfo = LLConstant::getNullValue(DtoType(getClassInfoType())); clssInfo = getNullPtr();
} }
// "catchpad within %switch [TypeDescriptor, 0, &caughtObject]" must be // "catchpad within %switch [TypeDescriptor, 0, &caughtObject]" must be
@ -662,7 +662,7 @@ TryCatchFinallyScopes::getLandingPadRef(CleanupCursor scope) {
namespace { namespace {
llvm::LandingPadInst *createLandingPadInst(IRState &irs) { llvm::LandingPadInst *createLandingPadInst(IRState &irs) {
LLType *retType = LLStructType::get(getVoidPtrType(irs.context()), LLType *retType = LLStructType::get(getOpaquePtrType(),
LLType::getInt32Ty(irs.context())); LLType::getInt32Ty(irs.context()));
if (!irs.func()->hasLLVMPersonalityFn()) { if (!irs.func()->hasLLVMPersonalityFn()) {
irs.func()->setLLVMPersonalityFn( irs.func()->setLLVMPersonalityFn(
@ -761,7 +761,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::emitLandingPad() {
llvm::AllocaInst *TryCatchFinallyScopes::getOrCreateEhPtrSlot() { llvm::AllocaInst *TryCatchFinallyScopes::getOrCreateEhPtrSlot() {
if (!ehPtrSlot) if (!ehPtrSlot)
ehPtrSlot = DtoRawAlloca(getVoidPtrType(), 0, "eh.ptr"); ehPtrSlot = DtoRawAlloca(getOpaquePtrType(), 0, "eh.ptr");
return ehPtrSlot; return ehPtrSlot;
} }
@ -773,7 +773,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::getOrCreateResumeUnwindBlock() {
irs.ir->SetInsertPoint(resumeUnwindBlock); irs.ir->SetInsertPoint(resumeUnwindBlock);
llvm::Function *resumeFn = getUnwindResumeFunction(Loc(), irs.module); llvm::Function *resumeFn = getUnwindResumeFunction(Loc(), irs.module);
irs.ir->CreateCall(resumeFn, DtoLoad(getVoidPtrType(), getOrCreateEhPtrSlot())); irs.ir->CreateCall(resumeFn, DtoLoad(getOpaquePtrType(), getOrCreateEhPtrSlot()));
irs.ir->CreateUnreachable(); irs.ir->CreateUnreachable();
irs.ir->SetInsertPoint(oldBB); irs.ir->SetInsertPoint(oldBB);

View file

@ -203,7 +203,7 @@ IrAggr::createInitializerConstant(const VarInitMap &explicitInitializers) {
// add monitor (except for C++ classes) // add monitor (except for C++ classes)
if (!cd->isCPPclass()) { if (!cd->isCPPclass()) {
constants.push_back(getNullValue(getVoidPtrType())); constants.push_back(getNullPtr());
offset += target.ptrsize; offset += target.ptrsize;
} }
} }

View file

@ -189,8 +189,6 @@ LLConstant *IrClass::getVtblInit() {
std::vector<llvm::Constant *> constants; std::vector<llvm::Constant *> constants;
constants.reserve(cd->vtbl.length); constants.reserve(cd->vtbl.length);
const auto voidPtrType = getVoidPtrType();
// start with the classinfo // start with the classinfo
llvm::Constant *c; llvm::Constant *c;
if (!cd->isCPPclass()) { if (!cd->isCPPclass()) {
@ -198,7 +196,7 @@ LLConstant *IrClass::getVtblInit() {
c = getClassInfoSymbol(); c = getClassInfoSymbol();
} else { } else {
// use null if there are no TypeInfos // use null if there are no TypeInfos
c = llvm::Constant::getNullValue(voidPtrType); c = getNullPtr();
} }
constants.push_back(c); constants.push_back(c);
} }
@ -213,7 +211,7 @@ LLConstant *IrClass::getVtblInit() {
assert(fd && "vtbl entry not a function"); assert(fd && "vtbl entry not a function");
if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody)) { if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody)) {
c = getNullValue(voidPtrType); c = getNullPtr();
} else { } else {
// If inferring return type and semantic3 has not been run, do it now. // If inferring return type and semantic3 has not been run, do it now.
// This pops up in some other places in the frontend as well, however // This pops up in some other places in the frontend as well, however
@ -224,7 +222,7 @@ LLConstant *IrClass::getVtblInit() {
if (fd->hasSemantic3Errors()) { if (fd->hasSemantic3Errors()) {
Logger::println( Logger::println(
"functionSemantic failed; using null for vtbl entry."); "functionSemantic failed; using null for vtbl entry.");
constants.push_back(getNullValue(voidPtrType)); constants.push_back(getNullPtr());
continue; continue;
} }
error(fd->loc, error(fd->loc,
@ -276,7 +274,7 @@ LLConstant *IrClass::getVtblInit() {
} }
// build the constant array // build the constant array
LLArrayType *vtblTy = LLArrayType::get(voidPtrType, constants.size()); LLArrayType *vtblTy = LLArrayType::get(getOpaquePtrType(), constants.size());
constVtbl = LLConstantArray::get(vtblTy, constants); constVtbl = LLConstantArray::get(vtblTy, constants);
return constVtbl; return constVtbl;
@ -471,7 +469,7 @@ llvm::GlobalVariable *IrClass::getInterfaceVtblSymbol(BaseClass *b,
gvar = it->second; gvar = it->second;
} else { } else {
llvm::Type *vtblType = llvm::Type *vtblType =
LLArrayType::get(getVoidPtrType(), b->sym->vtbl.length); LLArrayType::get(getOpaquePtrType(), b->sym->vtbl.length);
// Thunk prefix // Thunk prefix
char thunkPrefix[16]; char thunkPrefix[16];
@ -528,8 +526,6 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b,
char thunkPrefix[16]; char thunkPrefix[16];
snprintf(thunkPrefix, 16, "Thn%d_", b->offset); snprintf(thunkPrefix, 16, "Thn%d_", b->offset);
const auto voidPtrTy = getVoidPtrType();
if (!b->sym->isCPPinterface()) { // skip interface info for CPP interfaces if (!b->sym->isCPPinterface()) { // skip interface info for CPP interfaces
if (!suppressTypeInfo()) { if (!suppressTypeInfo()) {
// index into the interfaces array // index into the interfaces array
@ -543,7 +539,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b,
constants.push_back(c); constants.push_back(c);
} else { } else {
// use null if there are no TypeInfos // use null if there are no TypeInfos
constants.push_back(llvm::Constant::getNullValue(voidPtrTy)); constants.push_back(getNullPtr());
} }
} }
@ -555,7 +551,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b,
// FIXME // FIXME
// why is this null? // why is this null?
// happens for mini/s.d // happens for mini/s.d
constants.push_back(getNullValue(voidPtrTy)); constants.push_back(getNullPtr());
continue; continue;
} }
@ -678,7 +674,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b,
// build the vtbl constant // build the vtbl constant
llvm::Constant *vtbl_constant = LLConstantArray::get( llvm::Constant *vtbl_constant = LLConstantArray::get(
LLArrayType::get(voidPtrTy, constants.size()), constants); LLArrayType::get(getOpaquePtrType(), constants.size()), constants);
return vtbl_constant; return vtbl_constant;
} }
@ -746,7 +742,7 @@ LLConstant *IrClass::getClassInfoInterfaces() {
LLConstant *vtb; LLConstant *vtb;
// interface get a null // interface get a null
if (cd->isInterfaceDeclaration()) { if (cd->isInterfaceDeclaration()) {
vtb = DtoConstSlice(DtoConstSize_t(0), getNullValue(getVoidPtrType())); vtb = DtoConstSlice(DtoConstSize_t(0), getNullPtr());
} else { } else {
vtb = getInterfaceVtblSymbol(it, i); vtb = getInterfaceVtblSymbol(it, i);
auto vtblSize = itc->getVtblType()->getNumContainedTypes(); auto vtblSize = itc->getVtblType()->getNumContainedTypes();

View file

@ -135,7 +135,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
} else { } else {
llvm::Constant *initPtr; llvm::Constant *initPtr;
if (ts->isZeroInit(Loc())) { if (ts->isZeroInit(Loc())) {
initPtr = getNullValue(getVoidPtrType()); initPtr = getNullPtr();
} else { } else {
initPtr = getInitSymbol(); initPtr = getInitSymbol();
} }

View file

@ -24,7 +24,7 @@
IrTypeClass::IrTypeClass(ClassDeclaration *cd) IrTypeClass::IrTypeClass(ClassDeclaration *cd)
: IrTypeAggr(cd), cd(cd), tc(static_cast<TypeClass *>(cd->type)) { : IrTypeAggr(cd), cd(cd), tc(static_cast<TypeClass *>(cd->type)) {
vtbl_type = LLArrayType::get(getVoidPtrType(), cd->vtbl.length); vtbl_type = LLArrayType::get(getOpaquePtrType(), cd->vtbl.length);
} }
void IrTypeClass::addClassData(AggrTypeBuilder &builder, void IrTypeClass::addClassData(AggrTypeBuilder &builder,
@ -48,7 +48,7 @@ void IrTypeClass::addClassData(AggrTypeBuilder &builder,
// add to the interface map // add to the interface map
addInterfaceToMap(b->sym, builder.currentFieldIndex()); addInterfaceToMap(b->sym, builder.currentFieldIndex());
auto vtblTy = LLArrayType::get(getVoidPtrType(), b->sym->vtbl.length); auto vtblTy = LLArrayType::get(getOpaquePtrType(), b->sym->vtbl.length);
builder.addType(llvm::PointerType::get(vtblTy, 0), target.ptrsize); builder.addType(llvm::PointerType::get(vtblTy, 0), target.ptrsize);
++num_interface_vtbls; ++num_interface_vtbls;
@ -83,7 +83,7 @@ IrTypeClass *IrTypeClass::get(ClassDeclaration *cd) {
// classes have monitor and fields // classes have monitor and fields
if (!cd->isCPPclass() && !cd->isCPPinterface()) { if (!cd->isCPPclass() && !cd->isCPPinterface()) {
// add monitor // add monitor
builder.addType(getVoidPtrType(), target.ptrsize); builder.addType(getOpaquePtrType(), target.ptrsize);
} }
// add data members recursively // add data members recursively

View file

@ -56,7 +56,7 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) {
llvm::Type *ltf = llvm::Type *ltf =
DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid)); DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid));
llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace()); llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace());
llvm::Type *types[] = {getVoidPtrType(), fptr}; llvm::Type *types[] = {getOpaquePtrType(), fptr};
LLStructType *lt = LLStructType::get(gIR->context(), types, false); LLStructType *lt = LLStructType::get(gIR->context(), types, false);
// Could have already built the type as part of a struct forward reference, // Could have already built the type as part of a struct forward reference,