diff --git a/gen/abi/aarch64.cpp b/gen/abi/aarch64.cpp index e6d501c801..285bc56668 100644 --- a/gen/abi/aarch64.cpp +++ b/gen/abi/aarch64.cpp @@ -17,6 +17,8 @@ #include "gen/abi/abi.h" #include "gen/abi/generic.h" +using namespace dmd; + /** * AAPCS64 uses a special native va_list type, a struct aliased as * object.__va_list in druntime. Apple diverges and uses a simple char* @@ -100,7 +102,7 @@ public: if (!arg->byref) { auto tb = arg->type->toBasetype(); - if (tb->size() == 0) { + if (size(tb) == 0) { fty.args.erase(fty.args.begin() + i); continue; } diff --git a/gen/abi/abi.cpp b/gen/abi/abi.cpp index 5fb04c5330..1ecff84dcb 100644 --- a/gen/abi/abi.cpp +++ b/gen/abi/abi.cpp @@ -125,8 +125,8 @@ bool TargetABI::isPOD(Type *t, bool excludeStructsWithCtor) { } bool TargetABI::canRewriteAsInt(Type *t, bool include64bit) { - auto size = t->toBasetype()->size(); - return size == 1 || size == 2 || size == 4 || (include64bit && size == 8); + auto sz = size(t->toBasetype()); + return sz == 1 || sz == 2 || sz == 4 || (include64bit && sz == 8); } bool TargetABI::isExternD(TypeFunction *tf) { @@ -159,7 +159,7 @@ llvm::CallingConv::ID TargetABI::callingConv(FuncDeclaration *fdecl) { bool TargetABI::preferPassByRef(Type *t) { // simple base heuristic: use a ref for all types > 2 machine words - return t->size() > 2 * target.ptrsize; + return size(t) > 2 * target.ptrsize; } ////////////////////////////////////////////////////////////////////////////// diff --git a/gen/abi/arm.cpp b/gen/abi/arm.cpp index 21e8b3436f..8821ff8a34 100644 --- a/gen/abi/arm.cpp +++ b/gen/abi/arm.cpp @@ -18,6 +18,8 @@ #include "gen/abi/generic.h" #include "llvm/Target/TargetMachine.h" +using namespace dmd; + struct ArmTargetABI : TargetABI { HFVAToArray hfvaToArray; CompositeToArray32 compositeToArray32; @@ -36,7 +38,7 @@ struct ArmTargetABI : TargetABI { return true; return rt->ty == TY::Tsarray || - (rt->ty == TY::Tstruct && rt->size() > 4 && + (rt->ty == TY::Tstruct && size(rt) > 4 && (gTargetMachine->Options.FloatABIType == llvm::FloatABI::Soft || !isHFVA(rt, hfvaToArray.maxElements))); } @@ -47,7 +49,7 @@ struct ArmTargetABI : TargetABI { // converts back to non-byval. Without this special handling the // optimzer generates bad code (e.g. std.random unittest crash). t = t->toBasetype(); - return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && t->size() > 64); + return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && size(t) > 64); // Note: byval can have a codegen problem with -O1 and higher. // What happens is that load instructions are being incorrectly diff --git a/gen/abi/generic.h b/gen/abi/generic.h index 3647d8be79..4f8aa411a6 100644 --- a/gen/abi/generic.h +++ b/gen/abi/generic.h @@ -218,7 +218,7 @@ struct IntegerRewrite : BaseBitcastABIRewrite { return LLIntegerType::get(gIR->context(), size * 8); } - LLType *type(Type *t) override { return getIntegerType(t->size()); } + LLType *type(Type *t) override { return getIntegerType(dmd::size(t)); } }; ////////////////////////////////////////////////////////////////////////////// @@ -292,7 +292,7 @@ struct HFVAToArray : BaseBitcastABIRewrite { */ template struct CompositeToArray : BaseBitcastABIRewrite { LLType *type(Type *t) override { - size_t length = (t->size() + elementSize - 1) / elementSize; + size_t length = (dmd::size(t) + elementSize - 1) / elementSize; return LLArrayType::get(LLIntegerType::get(gIR->context(), elementSize * 8), length); } diff --git a/gen/abi/loongarch64.cpp b/gen/abi/loongarch64.cpp index 4141bd124f..b27a7b89be 100644 --- a/gen/abi/loongarch64.cpp +++ b/gen/abi/loongarch64.cpp @@ -64,7 +64,7 @@ FlattenedFields visitStructFields(Type *ty, unsigned baseOffset) { result.length = 2; break; default: - if (ty->size() > 8) { + if (size(ty) > 8) { // field larger than GRLEN and FRLEN result.length = -1; break; @@ -88,7 +88,7 @@ struct HardfloatRewrite : BaseBitcastABIRewrite { t[i] = flat.fields[i]->isfloating() ? DtoType(flat.fields[i]) - : LLIntegerType::get(gIR->context(), flat.fields[i]->size() * 8); + : LLIntegerType::get(gIR->context(), size(flat.fields[i]) * 8); } return LLStructType::get(gIR->context(), {t[0], t[1]}, false); } @@ -126,14 +126,14 @@ public: return true; } // pass by reference when > 2*GRLEN - return rt->size() > 16; + return size(rt) > 16; } auto passByVal(TypeFunction *, Type *t) -> bool override { if (!isPOD(t)) { return false; } - return t->size() > 16; + return size(t) > 16; } void rewriteFunctionType(IrFuncTy &fty) override { @@ -174,8 +174,8 @@ public: // return values should have the `signext` attribute. // C example: https://godbolt.org/z/vcjErxj76 arg.attrs.addAttribute(LLAttribute::SExt); - } else if (isAggregate(ty) && ty->size() && ty->size() <= 16) { - if (ty->size() > 8 && DtoAlignment(ty) < 16) { + } else if (isAggregate(ty) && size(ty) && size(ty) <= 16) { + if (size(ty) > 8 && DtoAlignment(ty) < 16) { // pass the aggregate as {int64, int64} to avoid wrong alignment integer2Rewrite.applyToIfNotObsolete(arg); } else { diff --git a/gen/abi/nvptx.cpp b/gen/abi/nvptx.cpp index c9978ec354..7c4878aaea 100644 --- a/gen/abi/nvptx.cpp +++ b/gen/abi/nvptx.cpp @@ -14,6 +14,8 @@ #include "gen/tollvm.h" #include "gen/dcompute/abi-rewrites.h" +using namespace dmd; + struct NVPTXTargetABI : TargetABI { DComputePointerRewrite pointerRewite; llvm::CallingConv::ID callingConv(LINK l) override { @@ -26,7 +28,7 @@ struct NVPTXTargetABI : TargetABI { } bool passByVal(TypeFunction *, Type *t) override { t = t->toBasetype(); - return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && t->size() > 64); + return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && size(t) > 64); } void rewriteFunctionType(IrFuncTy &fty) override { for (auto arg : fty.args) { diff --git a/gen/abi/ppc.cpp b/gen/abi/ppc.cpp index 34442ce999..81b1c9ce1b 100644 --- a/gen/abi/ppc.cpp +++ b/gen/abi/ppc.cpp @@ -26,6 +26,8 @@ #include "gen/llvmhelpers.h" #include "gen/tollvm.h" +using namespace dmd; + struct PPCTargetABI : TargetABI { CompositeToArray32 compositeToArray32; CompositeToArray64 compositeToArray64; @@ -54,7 +56,7 @@ struct PPCTargetABI : TargetABI { // used byval for type > 64 bytes. t = t->toBasetype(); return (t->ty == TY::Tsarray || t->ty == TY::Tstruct) && - (!Is64Bit || t->size() > 64); + (!Is64Bit || size(t) > 64); } void rewriteFunctionType(IrFuncTy &fty) override { diff --git a/gen/abi/ppc64le.cpp b/gen/abi/ppc64le.cpp index f644f827ed..129e1719bc 100644 --- a/gen/abi/ppc64le.cpp +++ b/gen/abi/ppc64le.cpp @@ -20,6 +20,8 @@ #include "gen/llvmhelpers.h" #include "gen/tollvm.h" +using namespace dmd; + struct PPC64LETargetABI : TargetABI { HFVAToArray hfvaToArray; CompositeToArray64 compositeToArray64; @@ -42,7 +44,7 @@ struct PPC64LETargetABI : TargetABI { bool passByVal(TypeFunction *, Type *t) override { t = t->toBasetype(); - return t->ty == TY::Tsarray || (t->ty == TY::Tstruct && t->size() > 16 && + return t->ty == TY::Tsarray || (t->ty == TY::Tstruct && size(t) > 16 && !isHFVA(t, hfvaToArray.maxElements)); } diff --git a/gen/abi/riscv64.cpp b/gen/abi/riscv64.cpp index 7c36eb100c..158bfaeba2 100644 --- a/gen/abi/riscv64.cpp +++ b/gen/abi/riscv64.cpp @@ -73,7 +73,7 @@ FlattenedFields visitStructFields(Type *ty, unsigned baseOffset) { result.length = 2; break; default: - if (ty->toBasetype()->size() > 8) { + if (size(ty->toBasetype()) > 8) { // field larger than XLEN and FLEN result.length = -1; break; @@ -111,7 +111,7 @@ struct HardfloatRewrite : ABIRewrite { for (unsigned i = 0; i < (unsigned)flat.length; ++i) { DtoMemCpy(DtoGEP(asType, buffer, 0, i), DtoGEP1(getI8Type(), address, flat.fields[i].offset), - DtoConstSize_t(flat.fields[i].ty->size())); + DtoConstSize_t(size(flat.fields[i].ty))); } return DtoLoad(asType, buffer, ".HardfloatRewrite_arg"); } @@ -127,7 +127,7 @@ struct HardfloatRewrite : ABIRewrite { for (unsigned i = 0; i < (unsigned)flat.length; ++i) { DtoMemCpy(DtoGEP1(getI8Type(), ret, flat.fields[i].offset), DtoGEP(asType, buffer, 0, i), - DtoConstSize_t(flat.fields[i].ty->size())); + DtoConstSize_t(size(flat.fields[i].ty))); } return ret; } @@ -142,7 +142,7 @@ struct HardfloatRewrite : ABIRewrite { t[i] = flat.fields[i].ty->isfloating() ? DtoType(flat.fields[i].ty) : LLIntegerType::get(gIR->context(), - flat.fields[i].ty->size() * 8); + size(flat.fields[i].ty) * 8); } return LLStructType::get(gIR->context(), {t[0], t[1]}, false); } @@ -167,20 +167,20 @@ public: return false; } Type *rt = tf->next->toBasetype(); - if (!rt->size()) + if (!size(rt)) return false; if (!isPOD(rt)) return true; - return rt->size() > 16; + return size(rt) > 16; } bool passByVal(TypeFunction *, Type *t) override { - if (!t->size()) + if (!size(t)) return false; if (t->toBasetype()->ty == TY::Tcomplex80) { // rewrite it later to bypass the RVal problem return false; } - return t->size() > 16; + return size(t) > 16; } void rewriteFunctionType(IrFuncTy &fty) override { if (!fty.ret->byref) { @@ -224,8 +224,8 @@ public: return; } - if (isAggregate(ty) && ty->size() && ty->size() <= 16) { - if (ty->size() > 8 && DtoAlignment(ty) < 16) { + if (isAggregate(ty) && size(ty) && size(ty) <= 16) { + if (size(ty) > 8 && DtoAlignment(ty) < 16) { // pass the aggregate as {int64, int64} to avoid wrong alignment integer2Rewrite.applyToIfNotObsolete(arg); } else { diff --git a/gen/abi/spirv.cpp b/gen/abi/spirv.cpp index d944b6fd2d..1dd09f3cd8 100644 --- a/gen/abi/spirv.cpp +++ b/gen/abi/spirv.cpp @@ -14,6 +14,8 @@ #include "gen/tollvm.h" #include "gen/dcompute/abi-rewrites.h" +using namespace dmd; + struct SPIRVTargetABI : TargetABI { DComputePointerRewrite pointerRewite; llvm::CallingConv::ID callingConv(LINK l) override { @@ -26,7 +28,7 @@ struct SPIRVTargetABI : TargetABI { } bool passByVal(TypeFunction *, Type *t) override { t = t->toBasetype(); - return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && t->size() > 64); + return ((t->ty == TY::Tsarray || t->ty == TY::Tstruct) && size(t) > 64); } void rewriteFunctionType(IrFuncTy &fty) override { for (auto arg : fty.args) { diff --git a/gen/abi/x86-64.cpp b/gen/abi/x86-64.cpp index 6018b38046..76b1039e82 100644 --- a/gen/abi/x86-64.cpp +++ b/gen/abi/x86-64.cpp @@ -216,7 +216,7 @@ bool X86_64TargetABI::returnInArg(TypeFunction *tf, bool) { // Prefer a ref if the POD cannot be passed in registers, i.e., if the LLVM // ByVal attribute would be applied, *and* the size is > 16. bool X86_64TargetABI::preferPassByRef(Type *t) { - return t->size() > 16 && passInMemory(t->toBasetype()); + return size(t) > 16 && passInMemory(t->toBasetype()); } bool X86_64TargetABI::passByVal(TypeFunction *tf, Type *t) { diff --git a/gen/abi/x86.cpp b/gen/abi/x86.cpp index 5965a7f38d..cd9acbe76f 100644 --- a/gen/abi/x86.cpp +++ b/gen/abi/x86.cpp @@ -20,6 +20,8 @@ #include "ir/irfunction.h" #include "ir/irfuncty.h" +using namespace dmd; + struct X86TargetABI : TargetABI { const bool isDarwin; const bool isMSVC; @@ -208,7 +210,7 @@ struct X86TargetABI : TargetABI { first.attrs.addAttribute(LLAttribute::InReg); } else { Type *firstTy = first.type->toBasetype(); - auto sz = firstTy->size(); + auto sz = size(firstTy); if (!firstTy->isfloating() && (sz == 1 || sz == 2 || sz == 4)) { // rewrite aggregates as integers to make inreg work if (firstTy->ty == TY::Tstruct || firstTy->ty == TY::Tsarray) { diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 716026331a..2ebdafcfbd 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -633,7 +633,7 @@ DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim, Type *eltType = arrayType->toBasetype()->nextOf(); - if (eltType->size() == 0) + if (size(eltType) == 0) return DtoNullValue(arrayType, loc)->isSlice(); // get runtime function @@ -989,8 +989,8 @@ DValue *DtoCastArray(const Loc &loc, DValue *u, Type *to) { ptr = DtoArrayPtr(u); } - const auto fsize = fromtype->nextOf()->size(); - const auto tsize = totype->nextOf()->size(); + const auto fsize = size(fromtype->nextOf()); + const auto tsize = size(totype->nextOf()); if (fsize != tsize) { if (auto constLength = isaConstantInt(length)) { // compute new constant length: (constLength * fsize) / tsize @@ -1023,7 +1023,7 @@ DValue *DtoCastArray(const Loc &loc, DValue *u, Type *to) { } else { size_t tosize = static_cast(totype)->dim->toInteger(); size_t i = - (tosize * totype->nextOf()->size() - 1) / fromtype->nextOf()->size(); + (tosize * size(totype->nextOf()) - 1) / size(fromtype->nextOf()); DConstValue index(Type::tsize_t, DtoConstSize_t(i)); DtoIndexBoundsCheck(loc, u, &index); ptr = DtoArrayPtr(u); diff --git a/gen/asm-x86.h b/gen/asm-x86.h index 2eb805a6d2..db148f39dd 100644 --- a/gen/asm-x86.h +++ b/gen/asm-x86.h @@ -3240,7 +3240,7 @@ struct AsmProcessor { (ty == TY::Tfloat80 || ty == TY::Timaginary80) && !global.params.targetTriple->isWindowsMSVCEnvironment() ? Extended_Ptr - : static_cast(v->type->size(Loc())); + : static_cast(dmd::size(v->type)); } if (!operand->symbolDisplacement.length) { diff --git a/gen/binops.cpp b/gen/binops.cpp index f4e4f34471..80064ecfd2 100644 --- a/gen/binops.cpp +++ b/gen/binops.cpp @@ -19,6 +19,8 @@ #include "gen/logger.h" #include "gen/tollvm.h" +using namespace dmd; + ////////////////////////////////////////////////////////////////////////////// namespace { @@ -91,7 +93,7 @@ DValue *emitPointerOffset(Loc loc, DValue *base, Expression *offset, if (byteOffset == 0) { llResult = llBase; } else { - const auto pointeeSize = pointeeType->size(loc); + const auto pointeeSize = size(pointeeType, loc); if (pointeeSize && byteOffset % pointeeSize == 0) { // can do a nice GEP llOffset = DtoConstSize_t(byteOffset / pointeeSize); } else { // need to cast base to i8* @@ -101,7 +103,7 @@ DValue *emitPointerOffset(Loc loc, DValue *base, Expression *offset, } } else { Expression *noStrideInc = - extractNoStrideInc(offset, pointeeType->size(loc), negateOffset); + extractNoStrideInc(offset, size(pointeeType, loc), negateOffset); auto rvals = evalSides(base, noStrideInc ? noStrideInc : offset, loadLhsAfterRhs); llBase = DtoRVal(rvals.lhs); diff --git a/gen/complex.cpp b/gen/complex.cpp index 109087e90a..af060af79d 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -20,6 +20,8 @@ #include "gen/logger.h" #include "gen/tollvm.h" +using namespace dmd; + //////////////////////////////////////////////////////////////////////////////// llvm::StructType *DtoComplexType(Type *type) { @@ -435,7 +437,7 @@ DValue *DtoCastComplex(const Loc &loc, DValue *val, Type *_to) { Type *to = _to->toBasetype(); Type *vty = val->type->toBasetype(); if (to->iscomplex()) { - if (vty->size() == to->size()) { + if (size(vty) == size(to)) { return val; } @@ -443,7 +445,7 @@ DValue *DtoCastComplex(const Loc &loc, DValue *val, Type *_to) { DtoGetComplexParts(loc, val->type, val, re, im); LLType *toty = DtoComplexBaseType(to); - if (to->size() < vty->size()) { + if (size(to) < size(vty)) { re = gIR->ir->CreateFPTrunc(re, toty); im = gIR->ir->CreateFPTrunc(im, toty); } else { diff --git a/gen/dcompute/targetOCL.cpp b/gen/dcompute/targetOCL.cpp index 0bc69a4943..e69aff40ea 100644 --- a/gen/dcompute/targetOCL.cpp +++ b/gen/dcompute/targetOCL.cpp @@ -39,6 +39,8 @@ "-v128:128:128-v192:256:256-v256:256:256" \ "-v512:512:512-v1024:1024:1024" +using namespace dmd; + namespace { class TargetOCL : public DComputeTarget { bool usedImage; @@ -157,7 +159,6 @@ public: ss << "uchar"; else if (ty == TY::Tvector) { TypeVector *vec = static_cast(t); - auto size = vec->size(Loc()); auto basety = vec->basetype->ty; if (basety == TY::Tint8) ss << "char"; @@ -165,7 +166,7 @@ public: ss << "uchar"; else ss << vec->basetype->toChars(); - ss << (int)size; + ss << (int)size(vec); } else ss << t->toChars(); return ss.str(); diff --git a/gen/functions.cpp b/gen/functions.cpp index ada3c8141d..8479359109 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -198,7 +198,7 @@ llvm::FunctionType *DtoFunctionType(Type *type, IrFuncTy &irFty, Type *thistype, attrs.addAttribute(LLAttribute::NonNull); attrs.addAttribute(LLAttribute::NoUndef); } else { - attrs.addDereferenceableAttr(loweredDType->size()); + attrs.addDereferenceableAttr(size(loweredDType)); } } else { if (abi->passByVal(f, loweredDType)) { diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0850aadbb8..a278c58edd 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -501,8 +501,8 @@ DValue *DtoCastInt(const Loc &loc, DValue *val, Type *_to) { return new DImValue(_to, rval); } - size_t fromsz = from->size(); - size_t tosz = to->size(); + size_t fromsz = size(from); + size_t tosz = size(to); if (to->ty == TY::Tbool) { LLValue *zero = LLConstantInt::get(rval->getType(), 0, false); @@ -584,8 +584,8 @@ DValue *DtoCastFloat(const Loc &loc, DValue *val, Type *to) { Type *fromtype = val->type->toBasetype(); assert(fromtype->isfloating()); - size_t fromsz = fromtype->size(); - size_t tosz = totype->size(); + size_t fromsz = size(fromtype); + size_t tosz = size(totype); LLValue *rval; @@ -656,7 +656,7 @@ DValue *DtoCastVector(const Loc &loc, DValue *val, Type *to) { LLValue *array = DtoAllocaDump(vector, tolltype, DtoAlignment(val->type)); return new DLValue(to, array); } - if (totype->ty == TY::Tvector && to->size() == val->type->size()) { + if (totype->ty == TY::Tvector && size(to) == size(val->type)) { return new DImValue(to, DtoBitCast(DtoRVal(val), tolltype)); } error(loc, "invalid cast from `%s` to `%s`", val->type->toChars(), @@ -918,7 +918,7 @@ void DtoVarDeclaration(VarDeclaration *vd) { if (isRealAlloca) { // The lifetime of a stack variable starts from the point it is declared gIR->funcGen().localVariableLifetimeAnnotator.addLocalVariable( - allocainst, DtoConstUlong(type->size())); + allocainst, DtoConstUlong(size(type))); } } @@ -1146,9 +1146,9 @@ LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp) { if (baseTargetType->ty == TY::Tsarray) { Logger::println("Building constant array initializer from scalar."); - assert(baseValType->size() > 0); - const auto numTotalVals = baseTargetType->size() / baseValType->size(); - assert(baseTargetType->size() % baseValType->size() == 0); + assert(size(baseValType) > 0); + const auto numTotalVals = size(baseTargetType) / size(baseValType); + assert(size(baseTargetType) % size(baseValType) == 0); // may be a multi-dimensional array init, e.g., `char[2][3] x = 0xff` baseValType = stripModifiers(baseValType); diff --git a/gen/naked.cpp b/gen/naked.cpp index 2eb338b94f..4d9ed26cc0 100644 --- a/gen/naked.cpp +++ b/gen/naked.cpp @@ -272,7 +272,7 @@ void emitABIReturnAsmStmt(IRAsmBlock *asmblock, const Loc &loc, if (triple.getArch() == llvm::Triple::x86) { if (rt->isintegral() || rt->ty == TY::Tpointer || rt->ty == TY::Tclass || rt->ty == TY::Taarray) { - if (rt->size() == 8) { + if (size(rt) == 8) { as->out.c = "=A,"; } else { as->out.c = "={ax},"; diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp index 92f4fddab9..9af923880f 100644 --- a/gen/toconstelem.cpp +++ b/gen/toconstelem.cpp @@ -199,7 +199,7 @@ public: const dinteger_t byteOffset = e->e2->toInteger(); LLConstant *llResult = nullptr; - const auto pointeeSize = pointeeType->size(e->loc); + const auto pointeeSize = size(pointeeType, e->loc); if (pointeeSize && byteOffset % pointeeSize == 0) { // can do a nice GEP LLConstant *llOffset = DtoConstSize_t(byteOffset / pointeeSize); if (negateOffset) @@ -286,11 +286,11 @@ public: StringExp *strexp = static_cast(e1); size_t datalen = strexp->sz * strexp->len; Type* eltype = tb->nextOf()->toBasetype(); - if (datalen % eltype->size() != 0) { + if (datalen % size(eltype) != 0) { error("the sizes don't line up"); return e1->toConstElem(p); } - size_t arrlen = datalen / eltype->size(); + size_t arrlen = datalen / size(eltype); #endif error( e->loc, diff --git a/gen/toir.cpp b/gen/toir.cpp index 003143f142..368fb094e3 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -97,7 +97,7 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd, // Skip zero-sized fields such as zero-length static arrays: `ubyte[0] // data`. - if (field->type->size() == 0) + if (size(field->type) == 0) continue; // the initializer expression may be null for overridden overlapping fields diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 18e8496d82..56989acb72 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -58,7 +58,7 @@ bool DtoIsReturnInArg(CallExp *ce) { void DtoAddExtendAttr(Type *type, llvm::AttrBuilder &attrs) { type = type->toBasetype(); - if (type->isintegral() && type->ty != TY::Tvector && type->size() <= 2) { + if (type->isintegral() && type->ty != TY::Tvector && size(type) <= 2) { attrs.addAttribute(type->isunsigned() ? LLAttribute::ZExt : LLAttribute::SExt); } diff --git a/ir/iraggr.cpp b/ir/iraggr.cpp index e99e3944a3..228cfe4983 100644 --- a/ir/iraggr.cpp +++ b/ir/iraggr.cpp @@ -171,7 +171,7 @@ static llvm::Constant *FillSArrayDims(Type *arrTypeD, llvm::Constant *init) { // the size without doing an expensive recursive D <-> LLVM type comparison. // The better way to solve this would be to just fix the initializer // codegen in any place where a scalar initializer might still be generated. - if (gDataLayout->getTypeAllocSize(init->getType()) >= arrTypeD->size()) { + if (gDataLayout->getTypeAllocSize(init->getType()) >= size(arrTypeD)) { return init; } diff --git a/ir/irtypeaggr.cpp b/ir/irtypeaggr.cpp index 21c1e9a10b..8f0e9724cc 100644 --- a/ir/irtypeaggr.cpp +++ b/ir/irtypeaggr.cpp @@ -17,6 +17,8 @@ #include "gen/llvmhelpers.h" #include "llvm/IR/DerivedTypes.h" +using namespace dmd; + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -97,7 +99,7 @@ void AggrTypeBuilder::addAggregate( bool haveExplicitInit = explicitInits && explicitInits->find(field) != explicitInits->end(); - uint64_t fieldSize = field->type->size(); + uint64_t fieldSize = size(field->type); const bool isBitField = field->isBitFieldDeclaration() != nullptr; if (isBitField) {