From a001ff6bd57802fd3c2dfea33d25d714da57d77d Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 22:07:13 +0200 Subject: [PATCH 1/8] Introduce getOpaquePtrType() helper --- gen/tollvm.cpp | 4 ++++ gen/tollvm.h | 1 + 2 files changed, 5 insertions(+) diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 18e8496d825..d76cb63ed61 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -689,6 +689,10 @@ llvm::GlobalVariable *isaGlobalVar(LLValue *v) { LLType *getI8Type() { return LLType::getInt8Ty(gIR->context()); } +LLPointerType *getOpaquePtrType(unsigned addressSpace) { + return LLPointerType::get(gIR->context(), addressSpace); +} + LLPointerType *getPtrToType(LLType *t) { if (t == LLType::getVoidTy(gIR->context())) t = LLType::getInt8Ty(gIR->context()); diff --git a/gen/tollvm.h b/gen/tollvm.h index fc2b9cfa1ea..f035e15f13d 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -150,6 +150,7 @@ LLGlobalVariable *isaGlobalVar(LLValue *v); // llvm::T::get(...) wrappers LLType *getI8Type(); +LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); LLPointerType *getPtrToType(LLType *t); LLPointerType *getVoidPtrType(); LLPointerType *getVoidPtrType(llvm::LLVMContext &C); From d5af843ba9bc434c59743e5cab449c8178d390ec Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 22:31:36 +0200 Subject: [PATCH 2/8] Remove getNullPtr() parameter --- gen/arrays.cpp | 4 ++-- gen/llvmhelpers.cpp | 5 ++--- gen/toconstelem.cpp | 2 +- gen/tollvm.cpp | 5 ++--- gen/tollvm.h | 2 +- gen/trycatchfinally.cpp | 2 +- ir/irclass.cpp | 5 +---- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 716026331a0..e77b2b3f534 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -936,7 +936,7 @@ LLValue *DtoArrayPtr(DValue *v) { if (t->ty == TY::Tarray) { if (v->isNull()) { - ptr = getNullPtr(wantedLLPtrType); + ptr = getNullPtr(); } else if (v->isLVal()) { ptr = DtoLoad(wantedLLPtrType, DtoGEP(DtoType(v->type), DtoLVal(v), 0, 1), ".ptr"); } else { @@ -1035,7 +1035,7 @@ DValue *DtoCastArray(const Loc &loc, DValue *u, Type *to) { if (totype->ty == TY::Tbool) { // return (arr.ptr !is null) LLValue *ptr = DtoArrayPtr(u); - LLConstant *nul = getNullPtr(ptr->getType()); + LLConstant *nul = getNullPtr(); return new DImValue(to, gIR->ir->CreateICmpNE(ptr, nul)); } diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0850aadbb84..9d4c95b0514 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -119,13 +119,12 @@ void DtoDeleteInterface(const Loc &loc, DValue *inst) { void DtoDeleteArray(const Loc &loc, DValue *arr) { llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_delarray_t"); - llvm::FunctionType *fty = fn->getFunctionType(); // the TypeInfo argument must be null if the type has no dtor Type *elementType = arr->type->nextOf(); bool hasDtor = (elementType->toBasetype()->ty == TY::Tstruct && elementType->needsDestruction()); - LLValue *typeInfo = !hasDtor ? getNullPtr(fty->getParamType(1)) + LLValue *typeInfo = !hasDtor ? getNullPtr() : DtoTypeInfoOf(loc, elementType); LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr)); @@ -478,7 +477,7 @@ DValue *DtoNullValue(Type *type, Loc loc) { // dynamic array if (basety == TY::Tarray) { LLValue *len = DtoConstSize_t(0); - LLValue *ptr = getNullPtr(DtoPtrToType(basetype->nextOf())); + LLValue *ptr = getNullPtr(); return new DSliceValue(type, len, ptr); } error(loc, "`null` not known for type `%s`", type->toChars()); diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp index 92f4fddab98..1e7fb936d2d 100644 --- a/gen/toconstelem.cpp +++ b/gen/toconstelem.cpp @@ -493,7 +493,7 @@ class ToConstElemVisitor : public Visitor { assert(result); if (fd->tok != TOK::function_) { - auto contextPtr = getNullPtr(getVoidPtrType()); + auto contextPtr = getNullPtr(); result = LLConstantStruct::getAnon(gIR->context(), {contextPtr, result}); } } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index d76cb63ed61..33bb7340794 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -707,9 +707,8 @@ LLPointerType *getVoidPtrType(llvm::LLVMContext &C) { return LLType::getInt8Ty(C)->getPointerTo(); } -llvm::ConstantPointerNull *getNullPtr(LLType *t) { - LLPointerType *pt = llvm::cast(t); - return llvm::ConstantPointerNull::get(pt); +llvm::ConstantPointerNull *getNullPtr() { + return llvm::ConstantPointerNull::get(getOpaquePtrType()); } LLConstant *getNullValue(LLType *t) { return LLConstant::getNullValue(t); } diff --git a/gen/tollvm.h b/gen/tollvm.h index f035e15f13d..8892c38b60b 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -154,7 +154,7 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); LLPointerType *getPtrToType(LLType *t); LLPointerType *getVoidPtrType(); LLPointerType *getVoidPtrType(llvm::LLVMContext &C); -llvm::ConstantPointerNull *getNullPtr(LLType *t); +llvm::ConstantPointerNull *getNullPtr(); LLConstant *getNullValue(LLType *t); // type sizes diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp index 59d79213e78..6583b389a33 100644 --- a/gen/trycatchfinally.cpp +++ b/gen/trycatchfinally.cpp @@ -832,7 +832,7 @@ TryCatchFinallyScopes::runCleanupPad(CleanupCursor scope, // preparation to allocate some space on the stack where _d_enter_cleanup // can place an exception frame (but not done here) - auto frame = getNullPtr(getVoidPtrType()); + auto frame = getNullPtr(); const auto savedInsertPoint = irs.saveInsertPoint(); diff --git a/ir/irclass.cpp b/ir/irclass.cpp index 34e1ef3d3e3..c53836d13ca 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -358,9 +358,6 @@ LLConstant *IrClass::getClassInfoInit() { RTTIBuilder b(cinfoType); - LLType *voidPtr = getVoidPtrType(); - LLType *voidPtrPtr = getPtrToType(voidPtr); - // adapted from original dmd code // byte[] m_init if (isInterface) { @@ -378,7 +375,7 @@ LLConstant *IrClass::getClassInfoInit() { // void*[] vtbl if (isInterface) { - b.push_array(0, getNullValue(voidPtrPtr)); + b.push_array(0, getNullPtr()); } else { b.push_array(cd->vtbl.length, getVtblSymbol()); } From 18709bb77f28119a8e2185bf4af887cedb3a1304 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 22:20:41 +0200 Subject: [PATCH 3/8] Replace getPtrToType() --- gen/arrays.cpp | 20 ++------------------ gen/arrays.h | 2 -- gen/functions.cpp | 2 +- gen/llvmhelpers.cpp | 4 ++-- gen/ms-cxx-helper.cpp | 8 ++++---- gen/ms-cxx-helper.h | 1 - gen/toir.cpp | 3 +-- gen/tollvm.cpp | 6 ------ gen/tollvm.h | 1 - 9 files changed, 10 insertions(+), 37 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index e77b2b3f534..da89ade7ff1 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -36,19 +36,6 @@ static void DtoSetArray(DValue *array, DValue *rhs); //////////////////////////////////////////////////////////////////////////////// -LLStructType *DtoArrayType(Type *arrayTy) { - assert(arrayTy->nextOf()); - llvm::Type *elems[] = {DtoSize_t(), DtoPtrToType(arrayTy->nextOf())}; - return llvm::StructType::get(gIR->context(), elems, false); -} - -LLStructType *DtoArrayType(LLType *t) { - llvm::Type *elems[] = {DtoSize_t(), getPtrToType(t)}; - return llvm::StructType::get(gIR->context(), elems, false); -} - -//////////////////////////////////////////////////////////////////////////////// - LLArrayType *DtoStaticArrayType(Type *t) { t = t->toBasetype(); assert(t->ty == TY::Tsarray); @@ -714,11 +701,8 @@ LLValue *DtoArrayEqCmp_impl(const Loc &loc, const char *func, DValue *l, LLSmallVector args; - // get values, reinterpret cast to void[] - args.push_back(DtoSlicePaint(DtoRVal(l), - DtoArrayType(LLType::getInt8Ty(gIR->context())))); - args.push_back(DtoSlicePaint(DtoRVal(r), - DtoArrayType(LLType::getInt8Ty(gIR->context())))); + args.push_back(DtoRVal(l)); + args.push_back(DtoRVal(r)); // pass array typeinfo ? if (useti) { diff --git a/gen/arrays.h b/gen/arrays.h index 9e38cb7fa40..4e2c7e52fd4 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -25,8 +25,6 @@ struct IRState; struct Loc; class Type; -llvm::StructType *DtoArrayType(Type *arrayTy); -llvm::StructType *DtoArrayType(LLType *elemTy); llvm::ArrayType *DtoStaticArrayType(Type *sarrayTy); /// Creates a (global) constant with the element data for the given arary diff --git a/gen/functions.cpp b/gen/functions.cpp index ada3c8141d8..8ae59b6e5ec 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -282,7 +282,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) { LLType *thisty = DtoType(dthis); // Logger::cout() << "this llvm type: " << *thisty << '\n'; if (ad->isStructDeclaration()) { - thisty = getPtrToType(thisty); + thisty = getOpaquePtrType(); } } else { IF_LOG Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 9d4c95b0514..9a9969190f7 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -646,7 +646,7 @@ DValue *DtoCastVector(const Loc &loc, DValue *val, Type *to) { LLValue *vector = DtoLVal(val); IF_LOG Logger::cout() << "src: " << *vector << " to type: " << *tolltype << " (casting address)\n"; - return new DLValue(to, DtoBitCast(vector, getPtrToType(tolltype))); + return new DLValue(to, vector); } LLValue *vector = DtoRVal(val); @@ -899,7 +899,7 @@ void DtoVarDeclaration(VarDeclaration *vd) { bool isRealAlloca = false; LLType *lltype = DtoType(type); // void for noreturn if (lltype->isVoidTy() || gDataLayout->getTypeSizeInBits(lltype) == 0) { - allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); + allocainst = getNullPtr(); } else if (type != vd->type) { allocainst = DtoAlloca(type, vd->toChars()); isRealAlloca = true; diff --git a/gen/ms-cxx-helper.cpp b/gen/ms-cxx-helper.cpp index 71ac41650ae..1272f534b36 100644 --- a/gen/ms-cxx-helper.cpp +++ b/gen/ms-cxx-helper.cpp @@ -142,7 +142,6 @@ bool isCatchSwitchBlock(llvm::BasicBlock *bb) { // routines for constructing the llvm types for MS RTTI structs. llvm::StructType *getTypeDescriptorType(IRState &irs, - llvm::Constant *classInfoPtr, llvm::StringRef TypeInfoString) { llvm::SmallString<256> TDTypeName("rtti.TypeDescriptor"); TDTypeName += llvm::utostr(TypeInfoString.size()); @@ -151,9 +150,10 @@ llvm::StructType *getTypeDescriptorType(IRState &irs, if (TypeDescriptorType) return TypeDescriptorType; auto int8Ty = LLType::getInt8Ty(gIR->context()); + auto ptrTy = getOpaquePtrType(); llvm::Type *FieldTypes[] = { - classInfoPtr->getType(), // CGM.Int8PtrPtrTy, - getPtrToType(int8Ty), // CGM.Int8PtrTy, + ptrTy, // CGM.Int8PtrPtrTy, + ptrTy, // CGM.Int8PtrTy, llvm::ArrayType::get(int8Ty, TypeInfoString.size() + 1)}; TypeDescriptorType = llvm::StructType::create(gIR->context(), FieldTypes, TDTypeName); @@ -188,7 +188,7 @@ llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { llvm::ConstantPointerNull::get(getVoidPtrType()), // Runtime data llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)}; llvm::StructType *TypeDescriptorType = - getTypeDescriptorType(irs, classInfoPtr, TypeNameString); + getTypeDescriptorType(irs, TypeNameString); const LinkageWithCOMDAT lwc = {LLGlobalVariable::LinkOnceODRLinkage, true}; Var = defineGlobal(cd->loc, gIR->module, TypeDescName, diff --git a/gen/ms-cxx-helper.h b/gen/ms-cxx-helper.h index 2eeee752169..dfc6086ad2a 100644 --- a/gen/ms-cxx-helper.h +++ b/gen/ms-cxx-helper.h @@ -12,7 +12,6 @@ #include "gen/irstate.h" llvm::StructType *getTypeDescriptorType(IRState &irs, - llvm::Constant *classInfoPtr, llvm::StringRef TypeInfoString); llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd); diff --git a/gen/toir.cpp b/gen/toir.cpp index 003143f142e..006bb9170cd 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2319,8 +2319,7 @@ class ToElemVisitor : public Visitor { // don't allocate storage for zero length dynamic array literals if (dyn && len == 0) { // dmd seems to just make them null... - result = new DSliceValue(e->type, DtoConstSize_t(0), - getNullPtr(getPtrToType(llElemType))); + result = new DSliceValue(e->type, DtoConstSize_t(0), getNullPtr()); return; } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 33bb7340794..9b2a8865873 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -693,12 +693,6 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace) { return LLPointerType::get(gIR->context(), addressSpace); } -LLPointerType *getPtrToType(LLType *t) { - if (t == LLType::getVoidTy(gIR->context())) - t = LLType::getInt8Ty(gIR->context()); - return t->getPointerTo(); -} - LLPointerType *getVoidPtrType() { return getVoidPtrType(gIR->context()); } diff --git a/gen/tollvm.h b/gen/tollvm.h index 8892c38b60b..5bd254a8e14 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -151,7 +151,6 @@ LLGlobalVariable *isaGlobalVar(LLValue *v); // llvm::T::get(...) wrappers LLType *getI8Type(); LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); -LLPointerType *getPtrToType(LLType *t); LLPointerType *getVoidPtrType(); LLPointerType *getVoidPtrType(llvm::LLVMContext &C); llvm::ConstantPointerNull *getNullPtr(); From f2fe3f51e5c798715d91e8f98864636ac5fb1322 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 22:46:17 +0200 Subject: [PATCH 4/8] Replace DtoPtrToType() --- gen/abi/generic.h | 2 +- gen/abi/x86-64.cpp | 2 +- gen/arrays.cpp | 5 +---- gen/dvalue.cpp | 9 +++------ gen/nested.cpp | 7 ++----- gen/tollvm.cpp | 14 +++----------- gen/tollvm.h | 2 -- 7 files changed, 11 insertions(+), 30 deletions(-) diff --git a/gen/abi/generic.h b/gen/abi/generic.h index 3647d8be79b..02c664e525e 100644 --- a/gen/abi/generic.h +++ b/gen/abi/generic.h @@ -250,7 +250,7 @@ struct IndirectByvalRewrite : ABIRewrite { return v; } - LLType *type(Type *t) override { return DtoPtrToType(t); } + LLType *type(Type *t) override { return getOpaquePtrType(); } void applyTo(IrFuncTyArg &arg, LLType *finalLType = nullptr) override { ABIRewrite::applyTo(arg, finalLType); diff --git a/gen/abi/x86-64.cpp b/gen/abi/x86-64.cpp index 6018b380469..de1fdbc9016 100644 --- a/gen/abi/x86-64.cpp +++ b/gen/abi/x86-64.cpp @@ -130,7 +130,7 @@ struct ImplicitByvalRewrite : ABIRewrite { LLValue *getLVal(Type *dty, LLValue *v) override { return v; } - LLType *type(Type *t) override { return DtoPtrToType(t); } + LLType *type(Type *t) override { return getOpaquePtrType(); } void applyTo(IrFuncTyArg &arg, LLType *finalLType = nullptr) override { ABIRewrite::applyTo(arg, finalLType); diff --git a/gen/arrays.cpp b/gen/arrays.cpp index da89ade7ff1..0f86908b4ea 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -913,16 +913,13 @@ LLValue *DtoArrayPtr(DValue *v) { LOG_SCOPE; Type *t = v->type->toBasetype(); - // v's LL array element type may not be the real one - // due to implicit casts (e.g., to base class) - LLType *wantedLLPtrType = DtoPtrToType(t->nextOf()); LLValue *ptr = nullptr; if (t->ty == TY::Tarray) { if (v->isNull()) { ptr = getNullPtr(); } else if (v->isLVal()) { - ptr = DtoLoad(wantedLLPtrType, DtoGEP(DtoType(v->type), DtoLVal(v), 0, 1), ".ptr"); + ptr = DtoLoad(getOpaquePtrType(), DtoGEP(DtoType(v->type), DtoLVal(v), 0, 1), ".ptr"); } else { auto slice = v->isSlice(); assert(slice); diff --git a/gen/dvalue.cpp b/gen/dvalue.cpp index 2673f891d86..08c0d3bab79 100644 --- a/gen/dvalue.cpp +++ b/gen/dvalue.cpp @@ -121,10 +121,7 @@ bool DFuncValue::definedInFuncEntryBB() { //////////////////////////////////////////////////////////////////////////////// DLValue::DLValue(Type *t, LLValue *v) : DValue(t, v) { - // v may be an addrspace qualified pointer so strip it before doing a pointer - // equality check. - assert(t->toBasetype()->ty == TY::Ttuple || - stripAddrSpaces(v->getType()) == DtoPtrToType(t)); + assert(t->toBasetype()->ty == TY::Ttuple || v->getType()->isPointerTy()); } DRValue *DLValue::getRVal() { @@ -163,11 +160,11 @@ DSpecialRefValue::DSpecialRefValue(Type *t, LLValue *v) : DLValue(v, t) { } DRValue *DSpecialRefValue::getRVal() { - return DLValue(type, DtoLoad(DtoPtrToType(type), val)).getRVal(); + return DLValue(type, DtoLoad(getOpaquePtrType(), val)).getRVal(); } DLValue *DSpecialRefValue::getLVal() { - return new DLValue(type, DtoLoad(DtoPtrToType(type), val)); + return new DLValue(type, DtoLoad(getOpaquePtrType(), val)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/gen/nested.cpp b/gen/nested.cpp index 36122e3f4b2..2226647b8de 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -82,7 +82,7 @@ DValue *DtoNestedVariable(const Loc &loc, Type *astype, VarDeclaration *vd, if (!fd) { error(loc, "function `%s` cannot access frame of function `%s`", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars()); - return new DLValue(astype, llvm::UndefValue::get(DtoPtrToType(astype))); + return new DLValue(astype, llvm::UndefValue::get(getOpaquePtrType())); } // is the nested variable in this scope? @@ -128,10 +128,7 @@ DValue *DtoNestedVariable(const Loc &loc, Type *astype, VarDeclaration *vd, if (irLocal->nestedIndex == -1) { Logger::println( "WARNING: isn't actually nested, using invalid null storage"); - auto llType = DtoPtrToType(astype); - if (isSpecialRefVar(vd)) - llType = llType->getPointerTo(); - return makeVarDValue(astype, vd, llvm::ConstantPointerNull::get(llType)); + return makeVarDValue(astype, vd, getNullPtr()); } //////////////////////////////////// diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 9b2a8865873..70ce2f394d2 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -200,8 +200,6 @@ LLType *DtoType(Type *t) { LLType *DtoMemType(Type *t) { return i1ToI8(voidToI8(DtoType(t))); } -LLPointerType *DtoPtrToType(Type *t) { return DtoMemType(t)->getPointerTo(); } - LLType *voidToI8(LLType *t) { return t->isVoidTy() ? LLType::getInt8Ty(t->getContext()) : t; } @@ -726,16 +724,10 @@ LLStructType *DtoModuleReferenceType() { return gIR->moduleRefType; } - // this is a recursive type so start out with a struct without body - LLStructType *st = LLStructType::create(gIR->context(), "ModuleReference"); - - // add members - LLType *types[] = {getPtrToType(st), DtoPtrToType(getModuleInfoType())}; - - // resolve type - st->setBody(types); + auto ptrType = getOpaquePtrType(); + LLType *elems[] = {ptrType, ptrType}; + auto st = LLStructType::get(gIR->context(), elems, "ModuleReference"); - // done gIR->moduleRefType = st; return st; } diff --git a/gen/tollvm.h b/gen/tollvm.h index 5bd254a8e14..b8bfff42988 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -34,8 +34,6 @@ LLType *DtoType(Type *t); // Uses DtoType(), but promotes i1 and void to i8. LLType *DtoMemType(Type *t); -// Returns a pointer to the type returned by DtoMemType(t). -LLPointerType *DtoPtrToType(Type *t); LLType *voidToI8(LLType *t); LLType *i1ToI8(LLType *t); From 0c1623c1a0eb6f1d1cd3dbdc904f0ba1a860ba33 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 23:08:43 +0200 Subject: [PATCH 5/8] Replace getVoidPtrType() --- driver/codegenerator.cpp | 6 +++--- gen/abi/x86-64.cpp | 12 ++++++------ gen/classes.cpp | 12 +++++------- gen/llvmhelpers.cpp | 6 +++--- gen/moduleinfo.cpp | 6 ++++-- gen/modules.cpp | 9 ++++----- gen/ms-cxx-helper.cpp | 4 ++-- gen/nested.cpp | 6 +++--- gen/rttibuilder.cpp | 4 ++-- gen/tocall.cpp | 6 ++++-- gen/toir.cpp | 2 +- gen/tollvm.cpp | 16 ++++------------ gen/tollvm.h | 2 -- gen/trycatchfinally.cpp | 16 ++++++++-------- ir/iraggr.cpp | 2 +- ir/irclass.cpp | 22 +++++++++------------- ir/irstruct.cpp | 2 +- ir/irtypeclass.cpp | 6 +++--- ir/irtypefunction.cpp | 2 +- 19 files changed, 64 insertions(+), 77 deletions(-) diff --git a/driver/codegenerator.cpp b/driver/codegenerator.cpp index 2881238960e..6c211a59685 100644 --- a/driver/codegenerator.cpp +++ b/driver/codegenerator.cpp @@ -109,14 +109,14 @@ void emitLLVMUsedArray(IRState &irs) { return; } - auto *i8PtrType = getVoidPtrType(irs.context()); + auto ptrType = LLPointerType::get(irs.context(), 0); // Convert all elements to i8* (the expected type for llvm.used) 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( irs.module, arrayType, false, llvm::GlobalValue::AppendingLinkage, llvm::ConstantArray::get(arrayType, irs.usedArray), "llvm.used"); diff --git a/gen/abi/x86-64.cpp b/gen/abi/x86-64.cpp index de1fdbc9016..253d0c2ab8c 100644 --- a/gen/abi/x86-64.cpp +++ b/gen/abi/x86-64.cpp @@ -336,13 +336,13 @@ void X86_64TargetABI::rewriteVarargs(IrFuncTy &fty, LLType *X86_64TargetABI::getValistType() { LLType *uintType = LLType::getInt32Ty(gIR->context()); - LLType *voidPointerType = getVoidPtrType(); + LLType *pointerType = getOpaquePtrType(); - std::vector parts; // struct __va_list_tag { - parts.push_back(uintType); // uint gp_offset; - parts.push_back(uintType); // uint fp_offset; - parts.push_back(voidPointerType); // void* overflow_arg_area; - parts.push_back(voidPointerType); // void* reg_save_area; } + std::vector parts; // struct __va_list_tag { + parts.push_back(uintType); // uint gp_offset; + parts.push_back(uintType); // uint fp_offset; + parts.push_back(pointerType); // void* overflow_arg_area; + parts.push_back(pointerType); // void* reg_save_area; } return LLStructType::get(gIR->context(), parts); } diff --git a/gen/classes.cpp b/gen/classes.cpp index 3ac7f2ef664..5d686f084df 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -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 // should be pretty cheap and perfectly safe even if the original was // null. - LLValue *isNull = gIR->ir->CreateICmpEQ( - orig, LLConstant::getNullValue(orig->getType()), ".nullcheck"); - v = gIR->ir->CreateSelect( - isNull, LLConstant::getNullValue(getVoidPtrType()), v, ".interface"); + const auto nullPtr = getNullPtr(); + LLValue *isNull = gIR->ir->CreateICmpEQ(orig, nullPtr, ".nullcheck"); + v = gIR->ir->CreateSelect(isNull, nullPtr, v, ".interface"); // return r-value return new DImValue(_to, v); } if (fc->sym->classKind == ClassKind::cpp) { Logger::println("C++ class/interface cast"); - LLValue *v = tc->sym->classKind == ClassKind::cpp - ? DtoRVal(val) - : LLConstant::getNullValue(getVoidPtrType()); + LLValue *v = + tc->sym->classKind == ClassKind::cpp ? DtoRVal(val) : getNullPtr(); return new DImValue(_to, v); } diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 9a9969190f7..85a1f7deead 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1570,9 +1570,9 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) { if (tb->ty != TY::Tstruct) { assert(tb->ty == TY::Tarray && tb->nextOf()->ty == TY::Tvoid); const auto size = DtoConstSize_t(ad->structsize); - llvm::Constant *ptr = sd && sd->zeroInit() - ? getNullValue(getVoidPtrType()) - : getIrAggr(ad)->getInitSymbol(); + LLConstant *ptr = sd && sd->zeroInit() + ? static_cast(getNullPtr()) + : getIrAggr(ad)->getInitSymbol(); return new DSliceValue(type, size, ptr); } diff --git a/gen/moduleinfo.cpp b/gen/moduleinfo.cpp index 3763a4554e4..f484ff89a54 100644 --- a/gen/moduleinfo.cpp +++ b/gen/moduleinfo.cpp @@ -173,7 +173,8 @@ llvm::Constant *buildImportedModules(Module *m, size_t &count) { if (importInits.empty()) 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); } @@ -207,7 +208,8 @@ llvm::Constant *buildLocalClasses(Module *m, size_t &count) { if (classInfoRefs.empty()) 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); } } diff --git a/gen/modules.cpp b/gen/modules.cpp index 6d0c3c4a68a..67191e1d9b8 100644 --- a/gen/modules.cpp +++ b/gen/modules.cpp @@ -136,8 +136,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, // provide the default initializer LLStructType *modulerefTy = DtoModuleReferenceType(); - LLConstant *mrefvalues[] = {LLConstant::getNullValue(getVoidPtrType()), - moduleinfo}; + LLConstant *mrefvalues[] = {getNullPtr(), moduleinfo}; LLConstant *thismrefinit = LLConstantStruct::get( modulerefTy, llvm::ArrayRef(mrefvalues)); @@ -149,10 +148,10 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, // make sure _Dmodule_ref is declared const auto mrefIRMangle = getIRMangledVarName("_Dmodule_ref", LINK::c); LLConstant *mref = gIR->module.getNamedGlobal(mrefIRMangle); - LLType *modulerefPtrTy = getVoidPtrType(); + LLType *ptrTy = getOpaquePtrType(); if (!mref) { mref = - declareGlobal(Loc(), gIR->module, modulerefPtrTy, mrefIRMangle, false, + declareGlobal(Loc(), gIR->module, ptrTy, mrefIRMangle, false, 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()); // 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 LLValue *gep = builder.CreateStructGEP( diff --git a/gen/ms-cxx-helper.cpp b/gen/ms-cxx-helper.cpp index 1272f534b36..d17cd3c6773 100644 --- a/gen/ms-cxx-helper.cpp +++ b/gen/ms-cxx-helper.cpp @@ -163,7 +163,7 @@ llvm::StructType *getTypeDescriptorType(IRState &irs, llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { if (cd->isCPPclass()) { 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, /*useDLLImport*/ cd->isExport()); } @@ -185,7 +185,7 @@ llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { // Declare and initialize the TypeDescriptor. llvm::Constant *Fields[] = { classInfoPtr, // VFPtr - llvm::ConstantPointerNull::get(getVoidPtrType()), // Runtime data + getNullPtr(), // Runtime data llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)}; llvm::StructType *TypeDescriptorType = getTypeDescriptorType(irs, TypeNameString); diff --git a/gen/nested.cpp b/gen/nested.cpp index 2226647b8de..0d22b5c0710 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -251,7 +251,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) { if (depth == -1 || (depth == 0 && !symfd->closureVars.empty())) { Logger::println("function does not have context or creates its own " "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()); fatal(); } - return llvm::ConstantPointerNull::get(getVoidPtrType()); + return getNullPtr(); } // The symbol may need a parent context of the current function. @@ -525,7 +525,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) { } if (depth > 1) { 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 // pointers diff --git a/gen/rttibuilder.cpp b/gen/rttibuilder.cpp index a08303aedcb..7110af0fa92 100644 --- a/gen/rttibuilder.cpp +++ b/gen/rttibuilder.cpp @@ -59,7 +59,7 @@ void RTTIBuilder::push(llvm::Constant *C) { 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)); } @@ -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_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) { diff --git a/gen/tocall.cpp b/gen/tocall.cpp index fc77c5f554d..97f5ca9f0cd 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -738,7 +738,9 @@ class ImplicitArgumentsBuilder { // ... or a delegate context arg LLValue *ctxarg; 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 { ctxarg = gIR->ir->CreateExtractValue(DtoRVal(fnval), 0, ".ptr"); } @@ -749,7 +751,7 @@ class ImplicitArgumentsBuilder { LLValue *contextptr = DtoNestedContext(loc, dfnval->func); args.push_back(contextptr); } else { - args.push_back(llvm::UndefValue::get(getVoidPtrType())); + args.push_back(llvm::UndefValue::get(getOpaquePtrType())); } } else { error(loc, "Context argument required but none given"); diff --git a/gen/toir.cpp b/gen/toir.cpp index 006bb9170cd..635761d52e5 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -795,7 +795,7 @@ class ToElemVisitor : public Visitor { if (canEmitVTableUnchangedAssumption && !dfnval->vtable && dfnval->vthis && dfnval->func->isVirtual()) { dfnval->vtable = - DtoLoad(getVoidPtrType(), dfnval->vthis, "saved_vtable"); + DtoLoad(getOpaquePtrType(), dfnval->vthis, "saved_vtable"); } } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 70ce2f394d2..90b6385d62d 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -187,7 +187,7 @@ LLType *DtoType(Type *t) { // associative arrays case TY::Taarray: - return getVoidPtrType(); + return getOpaquePtrType(); case TY::Tvector: 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) { // int memcmp ( const void * ptr1, const void * ptr2, size_t num ); - LLType *VoidPtrTy = getVoidPtrType(); LLFunction *fn = gIR->module.getFunction("memcmp"); if (!fn) { - LLType *Tys[] = {VoidPtrTy, VoidPtrTy, DtoSize_t()}; + LLType *ptrTy = getOpaquePtrType(); + LLType *Tys[] = {ptrTy, ptrTy, DtoSize_t()}; LLFunctionType *fty = LLFunctionType::get(LLType::getInt32Ty(gIR->context()), Tys, false); fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", @@ -581,7 +581,7 @@ LLType *stripAddrSpaces(LLType *t) if (!pt) return t; - return getVoidPtrType(); + return getOpaquePtrType(); } LLValue *DtoBitCast(LLValue *v, LLType *t, const llvm::Twine &name) { @@ -691,14 +691,6 @@ LLPointerType *getOpaquePtrType(unsigned 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() { return llvm::ConstantPointerNull::get(getOpaquePtrType()); } diff --git a/gen/tollvm.h b/gen/tollvm.h index b8bfff42988..f8e195d2ace 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -149,8 +149,6 @@ LLGlobalVariable *isaGlobalVar(LLValue *v); // llvm::T::get(...) wrappers LLType *getI8Type(); LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); -LLPointerType *getVoidPtrType(); -LLPointerType *getVoidPtrType(llvm::LLVMContext &C); llvm::ConstantPointerNull *getNullPtr(); LLConstant *getNullValue(LLType *t); diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp index 6583b389a33..3f982d93a0f 100644 --- a/gen/trycatchfinally.cpp +++ b/gen/trycatchfinally.cpp @@ -83,7 +83,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) { const auto enterCatchFn = getRuntimeFunction( c->loc, irs.module, 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); // 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) { const char *name = target.cpp.typeInfoMangle(p.cd); 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()); const auto cppTypeInfoPtrType = getCppTypeInfoPtrType(); @@ -230,7 +230,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch, exnObj = DtoAlloca(ctch->type, "exnObj"); } else { // catch all - exnObj = LLConstant::getNullValue(getVoidPtrType()); + exnObj = getNullPtr(); } bool isCPPclass = false; @@ -242,8 +242,8 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch, clssInfo = getIrAggr(cd)->getClassInfoSymbol(); } else { // catch all - typeDesc = LLConstant::getNullValue(getVoidPtrType()); - clssInfo = LLConstant::getNullValue(DtoType(getClassInfoType())); + typeDesc = getNullPtr(); + clssInfo = getNullPtr(); } // "catchpad within %switch [TypeDescriptor, 0, &caughtObject]" must be @@ -662,7 +662,7 @@ TryCatchFinallyScopes::getLandingPadRef(CleanupCursor scope) { namespace { llvm::LandingPadInst *createLandingPadInst(IRState &irs) { - LLType *retType = LLStructType::get(getVoidPtrType(irs.context()), + LLType *retType = LLStructType::get(getOpaquePtrType(), LLType::getInt32Ty(irs.context())); if (!irs.func()->hasLLVMPersonalityFn()) { irs.func()->setLLVMPersonalityFn( @@ -761,7 +761,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::emitLandingPad() { llvm::AllocaInst *TryCatchFinallyScopes::getOrCreateEhPtrSlot() { if (!ehPtrSlot) - ehPtrSlot = DtoRawAlloca(getVoidPtrType(), 0, "eh.ptr"); + ehPtrSlot = DtoRawAlloca(getOpaquePtrType(), 0, "eh.ptr"); return ehPtrSlot; } @@ -773,7 +773,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::getOrCreateResumeUnwindBlock() { irs.ir->SetInsertPoint(resumeUnwindBlock); 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->SetInsertPoint(oldBB); diff --git a/ir/iraggr.cpp b/ir/iraggr.cpp index e99e3944a3f..9f8c1730c9d 100644 --- a/ir/iraggr.cpp +++ b/ir/iraggr.cpp @@ -203,7 +203,7 @@ IrAggr::createInitializerConstant(const VarInitMap &explicitInitializers) { // add monitor (except for C++ classes) if (!cd->isCPPclass()) { - constants.push_back(getNullValue(getVoidPtrType())); + constants.push_back(getNullPtr()); offset += target.ptrsize; } } diff --git a/ir/irclass.cpp b/ir/irclass.cpp index c53836d13ca..0db3d2039fa 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -189,8 +189,6 @@ LLConstant *IrClass::getVtblInit() { std::vector constants; constants.reserve(cd->vtbl.length); - const auto voidPtrType = getVoidPtrType(); - // start with the classinfo llvm::Constant *c; if (!cd->isCPPclass()) { @@ -198,7 +196,7 @@ LLConstant *IrClass::getVtblInit() { c = getClassInfoSymbol(); } else { // use null if there are no TypeInfos - c = llvm::Constant::getNullValue(voidPtrType); + c = getNullPtr(); } constants.push_back(c); } @@ -213,7 +211,7 @@ LLConstant *IrClass::getVtblInit() { assert(fd && "vtbl entry not a function"); if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody)) { - c = getNullValue(voidPtrType); + c = getNullPtr(); } else { // 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 @@ -224,7 +222,7 @@ LLConstant *IrClass::getVtblInit() { if (fd->hasSemantic3Errors()) { Logger::println( "functionSemantic failed; using null for vtbl entry."); - constants.push_back(getNullValue(voidPtrType)); + constants.push_back(getNullPtr()); continue; } error(fd->loc, @@ -276,7 +274,7 @@ LLConstant *IrClass::getVtblInit() { } // build the constant array - LLArrayType *vtblTy = LLArrayType::get(voidPtrType, constants.size()); + LLArrayType *vtblTy = LLArrayType::get(getOpaquePtrType(), constants.size()); constVtbl = LLConstantArray::get(vtblTy, constants); return constVtbl; @@ -471,7 +469,7 @@ llvm::GlobalVariable *IrClass::getInterfaceVtblSymbol(BaseClass *b, gvar = it->second; } else { llvm::Type *vtblType = - LLArrayType::get(getVoidPtrType(), b->sym->vtbl.length); + LLArrayType::get(getOpaquePtrType(), b->sym->vtbl.length); // Thunk prefix char thunkPrefix[16]; @@ -528,8 +526,6 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, char thunkPrefix[16]; snprintf(thunkPrefix, 16, "Thn%d_", b->offset); - const auto voidPtrTy = getVoidPtrType(); - if (!b->sym->isCPPinterface()) { // skip interface info for CPP interfaces if (!suppressTypeInfo()) { // index into the interfaces array @@ -543,7 +539,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, constants.push_back(c); } else { // 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 // why is this null? // happens for mini/s.d - constants.push_back(getNullValue(voidPtrTy)); + constants.push_back(getNullPtr()); continue; } @@ -678,7 +674,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, // build the vtbl constant llvm::Constant *vtbl_constant = LLConstantArray::get( - LLArrayType::get(voidPtrTy, constants.size()), constants); + LLArrayType::get(getOpaquePtrType(), constants.size()), constants); return vtbl_constant; } @@ -746,7 +742,7 @@ LLConstant *IrClass::getClassInfoInterfaces() { LLConstant *vtb; // interface get a null if (cd->isInterfaceDeclaration()) { - vtb = DtoConstSlice(DtoConstSize_t(0), getNullValue(getVoidPtrType())); + vtb = DtoConstSlice(DtoConstSize_t(0), getNullPtr()); } else { vtb = getInterfaceVtblSymbol(it, i); auto vtblSize = itc->getVtblType()->getNumContainedTypes(); diff --git a/ir/irstruct.cpp b/ir/irstruct.cpp index 17bdba45618..1b0f4003c0d 100644 --- a/ir/irstruct.cpp +++ b/ir/irstruct.cpp @@ -135,7 +135,7 @@ LLConstant *IrStruct::getTypeInfoInit() { } else { llvm::Constant *initPtr; if (ts->isZeroInit(Loc())) { - initPtr = getNullValue(getVoidPtrType()); + initPtr = getNullPtr(); } else { initPtr = getInitSymbol(); } diff --git a/ir/irtypeclass.cpp b/ir/irtypeclass.cpp index 365be66a1f2..e29b7460706 100644 --- a/ir/irtypeclass.cpp +++ b/ir/irtypeclass.cpp @@ -24,7 +24,7 @@ IrTypeClass::IrTypeClass(ClassDeclaration *cd) : IrTypeAggr(cd), cd(cd), tc(static_cast(cd->type)) { - vtbl_type = LLArrayType::get(getVoidPtrType(), cd->vtbl.length); + vtbl_type = LLArrayType::get(getOpaquePtrType(), cd->vtbl.length); } void IrTypeClass::addClassData(AggrTypeBuilder &builder, @@ -48,7 +48,7 @@ void IrTypeClass::addClassData(AggrTypeBuilder &builder, // add to the interface map 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); ++num_interface_vtbls; @@ -83,7 +83,7 @@ IrTypeClass *IrTypeClass::get(ClassDeclaration *cd) { // classes have monitor and fields if (!cd->isCPPclass() && !cd->isCPPinterface()) { // add monitor - builder.addType(getVoidPtrType(), target.ptrsize); + builder.addType(getOpaquePtrType(), target.ptrsize); } // add data members recursively diff --git a/ir/irtypefunction.cpp b/ir/irtypefunction.cpp index dd124a1c9c4..93629b2acfa 100644 --- a/ir/irtypefunction.cpp +++ b/ir/irtypefunction.cpp @@ -56,7 +56,7 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) { llvm::Type *ltf = DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid)); 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); // Could have already built the type as part of a struct forward reference, From 6bfa6d9adbe48cf8f9c98df6201b5cef0c66b11a Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 18 Jul 2024 23:35:09 +0200 Subject: [PATCH 6/8] [remove dead code] --- gen/functions.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index 8ae59b6e5ec..55174bb6acc 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -279,11 +279,6 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) { if (AggregateDeclaration *ad = fdecl->isMember2()) { IF_LOG Logger::println("isMember = this is: %s", ad->type->toChars()); dthis = ad->type; - LLType *thisty = DtoType(dthis); - // Logger::cout() << "this llvm type: " << *thisty << '\n'; - if (ad->isStructDeclaration()) { - thisty = getOpaquePtrType(); - } } else { IF_LOG Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); From 90bcdbf140bd0c678d2311021f12a82ef2b08010 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 21 Jul 2024 08:51:29 +0200 Subject: [PATCH 7/8] Bump used Android NDK to r27 (#4711) --- .github/actions/3-build-cross/action.yml | 4 ++-- CHANGELOG.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/3-build-cross/action.yml b/.github/actions/3-build-cross/action.yml index f99c34b4d36..55713d2bd0d 100644 --- a/.github/actions/3-build-cross/action.yml +++ b/.github/actions/3-build-cross/action.yml @@ -14,7 +14,7 @@ inputs: default: false android_ndk_version: required: false - default: r26d + default: r27 android_api_level: required: false default: 29 @@ -104,7 +104,7 @@ runs: triple="$arch-linux-androideabi$apiLevel" cmakeFlags+=' -DANDROID_ABI=armeabi-v7a' elif [[ "$arch" == aarch64 ]]; then - # FIXME: as of NDK rc26d, libc.a has __tls_get_addr, but libc.so only since API level 30 (Android v11) + # FIXME: as of NDK r27, libc.a has __tls_get_addr, but libc.so only since API level 30 (Android v11) apiLevel=30 triple="$arch-linux-android$apiLevel" cmakeFlags+=' -DANDROID_ABI=arm64-v8a' diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e107b8f2f..22cf17ed9f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # LDC master #### Big news +- Android: NDK for prebuilt package bumped from r26d to r27. (#4711) #### Platform support From 48c1dff0466f5231619356ae33ef1a181888a1ff Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Tue, 30 Jul 2024 23:05:44 +0700 Subject: [PATCH 8/8] druntime CMake: ASM language added to project (#4715) Sometimes CMake silently(!) ignores .S (asm) files if ASM isn't mentioned in the project directive. https://stackoverflow.com/questions/23452089/why-is-cmake-ignoring-assembly-files-when-building-static-library/67902603#67902603 --- runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index b392acb8bbc..ca9e50f2516 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1,4 +1,4 @@ -project(runtime C) +project(runtime C ASM) cmake_minimum_required(VERSION 3.4.3)