diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index a9c4b9f6df649f..1a90b945eb2bfe 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -600,8 +600,7 @@ enum AttributeProperty { static bool hasAttributeProperty(Attribute::AttrKind Kind, AttributeProperty Prop) { unsigned Index = Kind - 1; - assert(Index < sizeof(AttrPropTable) / sizeof(AttrPropTable[0]) && - "Invalid attribute kind"); + assert(Index < std::size(AttrPropTable) && "Invalid attribute kind"); return AttrPropTable[Index] & Prop; } diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp index 3e82987801c7f1..2d1440756a95cf 100644 --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -570,8 +570,7 @@ void ModuleSummaryIndex::exportToDot( " [color=brown]; // call (hotness : Hot)", " [style=bold,color=red]; // call (hotness : Critical)"}; - assert(static_cast(TypeOrHotness) < - sizeof(EdgeAttrs) / sizeof(EdgeAttrs[0])); + assert(static_cast(TypeOrHotness) < std::size(EdgeAttrs)); OS << Pfx << NodeId(SrcMod, SrcId) << " -> " << NodeId(DstMod, DstId) << EdgeAttrs[TypeOrHotness] << "\n"; }; diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index de632695ca499f..bbea275ab445e6 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -490,7 +490,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) { {CSSummaryOffset, reinterpret_cast(TheCSSummary.get()), (int)CSSummarySize}}; - OS.patch(PatchItems, sizeof(PatchItems) / sizeof(*PatchItems)); + OS.patch(PatchItems, std::size(PatchItems)); for (const auto &I : FunctionData) for (const auto &F : I.getValue()) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp index dafbeaeaec528f..b0099ffd18a124 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp @@ -57,8 +57,7 @@ static constexpr const FeatureBitset TargetFeatures = { // TODO: Support conservative min/max merging instead of cloning. static constexpr const char *AttributeNames[] = {"amdgpu-waves-per-eu"}; -static constexpr unsigned NumAttr = - sizeof(AttributeNames) / sizeof(AttributeNames[0]); +static constexpr unsigned NumAttr = std::size(AttributeNames); class AMDGPUPropagateAttributes { diff --git a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp index 8792ce354c061c..de6ca0aa9cbb40 100644 --- a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp +++ b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp @@ -807,7 +807,7 @@ static const uint16_t SysRegDecoderTable[] = { static DecodeStatus DecodeSysRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/, const MCDisassembler *Decoder) { - if (RegNo >= sizeof(SysRegDecoderTable) / sizeof(SysRegDecoderTable[0])) + if (RegNo >= std::size(SysRegDecoderTable)) return MCDisassembler::Fail; if (SysRegDecoderTable[RegNo] == Hexagon::NoRegister) @@ -835,7 +835,7 @@ static DecodeStatus DecodeSysRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/, const MCDisassembler *Decoder) { RegNo = RegNo >> 1; - if (RegNo >= sizeof(SysReg64DecoderTable) / sizeof(SysReg64DecoderTable[0])) + if (RegNo >= std::size(SysReg64DecoderTable)) return MCDisassembler::Fail; if (SysReg64DecoderTable[RegNo] == Hexagon::NoRegister) diff --git a/llvm/lib/Target/Lanai/LanaiISelLowering.cpp b/llvm/lib/Target/Lanai/LanaiISelLowering.cpp index b80c68e251e4b3..d5639bd9a329cc 100644 --- a/llvm/lib/Target/Lanai/LanaiISelLowering.cpp +++ b/llvm/lib/Target/Lanai/LanaiISelLowering.cpp @@ -951,8 +951,7 @@ SDValue LanaiTargetLowering::LowerMUL(SDValue Op, SelectionDAG &DAG) const { // Assemble multiplication from shift, add, sub using NAF form and running // sum. - for (unsigned int I = 0; I < sizeof(SignedDigit) / sizeof(SignedDigit[0]); - ++I) { + for (unsigned int I = 0; I < std::size(SignedDigit); ++I) { if (SignedDigit[I] == 0) continue; diff --git a/llvm/lib/Target/PowerPC/PPCCallingConv.cpp b/llvm/lib/Target/PowerPC/PPCCallingConv.cpp index cd67a09ae9358f..ff792fda8fb2d5 100644 --- a/llvm/lib/Target/PowerPC/PPCCallingConv.cpp +++ b/llvm/lib/Target/PowerPC/PPCCallingConv.cpp @@ -120,7 +120,7 @@ static bool CC_PPC32_SPE_CustomSplitFP64(unsigned &ValNo, MVT &ValVT, return false; unsigned i; - for (i = 0; i < sizeof(HiRegList) / sizeof(HiRegList[0]); ++i) + for (i = 0; i < std::size(HiRegList); ++i) if (HiRegList[i] == Reg) break; @@ -149,7 +149,7 @@ static bool CC_PPC32_SPE_RetF64(unsigned &ValNo, MVT &ValVT, return false; unsigned i; - for (i = 0; i < sizeof(HiRegList) / sizeof(HiRegList[0]); ++i) + for (i = 0; i < std::size(HiRegList); ++i) if (HiRegList[i] == Reg) break; diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp index 8e46219460080f..cc65b95a00d4f1 100644 --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp @@ -222,7 +222,7 @@ void SparcInstPrinter::printMembarTag(const MCInst *MI, int opNum, } bool First = true; - for (unsigned i = 0; i < sizeof(TagNames) / sizeof(char *); i++) { + for (unsigned i = 0; i < std::size(TagNames); i++) { if (Imm & (1 << i)) { O << (First ? "" : " | ") << TagNames[i]; First = false; diff --git a/llvm/lib/Target/X86/X86CallingConv.cpp b/llvm/lib/Target/X86/X86CallingConv.cpp index ded93fdc011cfa..ad61334643f852 100644 --- a/llvm/lib/Target/X86/X86CallingConv.cpp +++ b/llvm/lib/Target/X86/X86CallingConv.cpp @@ -240,7 +240,7 @@ static bool CC_X86_32_MCUInReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT, // This is similar to CCAssignToReg<[EAX, EDX, ECX]>, but makes sure // not to split i64 and double between a register and stack static const MCPhysReg RegList[] = {X86::EAX, X86::EDX, X86::ECX}; - static const unsigned NumRegs = sizeof(RegList) / sizeof(RegList[0]); + static const unsigned NumRegs = std::size(RegList); SmallVectorImpl &PendingMembers = State.getPendingLocs(); diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 76f7136c3d7e4e..2c0fb3584dec48 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1031,7 +1031,7 @@ unsigned HWAddressSanitizer::retagMask(unsigned AllocaNo) { 48, 16, 120, 248, 56, 24, 8, 124, 252, 60, 28, 12, 4, 126, 254, 62, 30, 14, 6, 2, 127, 63, 31, 15, 7, 3, 1}; - return FastMasks[AllocaNo % (sizeof(FastMasks) / sizeof(FastMasks[0]))]; + return FastMasks[AllocaNo % std::size(FastMasks)]; } Value *HWAddressSanitizer::applyTagMask(IRBuilder<> &IRB, Value *OldTag) { diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp index c60efa465bb696..a68ca198e5573a 100644 --- a/llvm/lib/XRay/InstrumentationMap.cpp +++ b/llvm/lib/XRay/InstrumentationMap.cpp @@ -188,7 +188,7 @@ loadObj(StringRef Filename, object::OwningBinary &ObjFile, SledEntry::FunctionKinds::TAIL, SledEntry::FunctionKinds::LOG_ARGS_ENTER, SledEntry::FunctionKinds::CUSTOM_EVENT}; - if (Kind >= sizeof(Kinds) / sizeof(Kinds[0])) + if (Kind >= std::size(Kinds)) return errorCodeToError( std::make_error_code(std::errc::executable_format_error)); Entry.Kind = Kinds[Kind]; diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp index 2f8275978455f9..6ecb6b17f20711 100644 --- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp @@ -709,8 +709,7 @@ class ExegesisX86Target : public ExegesisTarget { ArrayRef getUnavailableRegisters() const override { return makeArrayRef(kUnavailableRegisters, - sizeof(kUnavailableRegisters) / - sizeof(kUnavailableRegisters[0])); + std::size(kUnavailableRegisters)); } bool allowAsBackToBack(const Instruction &Instr) const override { diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp index fdfb5de658dd49..19c9830c056257 100644 --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -756,7 +756,7 @@ void COFFDumper::printPEHeader(const PEHeader *Hdr) { }; for (uint32_t i = 0; i < Hdr->NumberOfRvaAndSize; ++i) - if (i < sizeof(directory) / sizeof(char *)) + if (i < std::size(directory)) printDataDirectory(i, directory[i]); else printDataDirectory(i, "Unknown"); diff --git a/llvm/unittests/ADT/SimpleIListTest.cpp b/llvm/unittests/ADT/SimpleIListTest.cpp index 17dd140c0a4da1..c2992baf8a5f7d 100644 --- a/llvm/unittests/ADT/SimpleIListTest.cpp +++ b/llvm/unittests/ADT/SimpleIListTest.cpp @@ -634,7 +634,7 @@ TEST(SimpleIListTest, TaggedLists) { L2.push_back(Ns[I]); // Check that each list is correct. - EXPECT_EQ(sizeof(Order1) / sizeof(int), L1.size()); + EXPECT_EQ(std::size(Order1), L1.size()); auto I1 = L1.begin(); for (int I : Order1) { EXPECT_EQ(Ns[I].getIterator1(), I1); @@ -642,7 +642,7 @@ TEST(SimpleIListTest, TaggedLists) { } EXPECT_EQ(L1.end(), I1); - EXPECT_EQ(sizeof(Order2) / sizeof(int), L2.size()); + EXPECT_EQ(std::size(Order2), L2.size()); auto I2 = L2.begin(); for (int I : Order2) { EXPECT_EQ(Ns[I].getIterator2(), I2); diff --git a/llvm/unittests/BinaryFormat/TestFileMagic.cpp b/llvm/unittests/BinaryFormat/TestFileMagic.cpp index 235e4bb05f0943..b09a2c07309f82 100644 --- a/llvm/unittests/BinaryFormat/TestFileMagic.cpp +++ b/llvm/unittests/BinaryFormat/TestFileMagic.cpp @@ -128,7 +128,7 @@ TEST_F(MagicTest, Magic) { }; // Create some files filled with magic. - for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; + for (type *i = types, *e = types + std::size(types); i != e; ++i) { SmallString<128> file_pathname(TestDirectory); llvm::sys::path::append(file_pathname, i->filename); diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index aa71afeaf2c6fa..cbc04d2919c8bb 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -1112,7 +1112,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_module_test) { StringRef Funcs[] = {"Gfoo", "Gblah", "Gbar", "Ifoo", "Iblah", "Ibar", "Pfoo", "Pblah", "Pbar", "Wfoo", "Wblah", "Wbar"}; - for (unsigned I = 0; I < sizeof(Funcs) / sizeof(*Funcs); I++) { + for (unsigned I = 0; I < std::size(Funcs); I++) { Function *F = M->getFunction(Funcs[I]); ASSERT_TRUE(F != nullptr); std::string PGOName = getPGOFuncName(*F); diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index df33e5309945aa..0d0b6ec471ebc4 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -740,7 +740,7 @@ TEST(CommandLineTest, DefaultOptions) { StackOption SC2_Foo("foo", cl::sub(SC2)); const char *args0[] = {"prog", "-b", "args0 bar string", "-f"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(sizeof(args0) / sizeof(char *), args0, + EXPECT_TRUE(cl::ParseCommandLineOptions(std::size(args0), args0, StringRef(), &llvm::nulls())); EXPECT_EQ(Bar, "args0 bar string"); EXPECT_TRUE(Foo); @@ -750,7 +750,7 @@ TEST(CommandLineTest, DefaultOptions) { cl::ResetAllOptionOccurrences(); const char *args1[] = {"prog", "sc1", "-b", "-bar", "args1 bar string", "-f"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(sizeof(args1) / sizeof(char *), args1, + EXPECT_TRUE(cl::ParseCommandLineOptions(std::size(args1), args1, StringRef(), &llvm::nulls())); EXPECT_EQ(Bar, "args1 bar string"); EXPECT_TRUE(Foo); @@ -766,7 +766,7 @@ TEST(CommandLineTest, DefaultOptions) { const char *args2[] = {"prog", "sc2", "-b", "args2 bar string", "-f", "-foo", "foo string"}; - EXPECT_TRUE(cl::ParseCommandLineOptions(sizeof(args2) / sizeof(char *), args2, + EXPECT_TRUE(cl::ParseCommandLineOptions(std::size(args2), args2, StringRef(), &llvm::nulls())); EXPECT_EQ(Bar, "args2 bar string"); EXPECT_TRUE(Foo); diff --git a/llvm/unittests/TextAPI/TextStubV1Tests.cpp b/llvm/unittests/TextAPI/TextStubV1Tests.cpp index a7995df346f8b1..e2c6cd204e1ecf 100644 --- a/llvm/unittests/TextAPI/TextStubV1Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV1Tests.cpp @@ -104,7 +104,7 @@ TEST(TBDv1, ReadFile) { } llvm::sort(Exports); - EXPECT_EQ(sizeof(TBDv1Symbols) / sizeof(ExportedSymbol), Exports.size()); + EXPECT_EQ(std::size(TBDv1Symbols), Exports.size()); EXPECT_TRUE( std::equal(Exports.begin(), Exports.end(), std::begin(TBDv1Symbols))); diff --git a/llvm/unittests/TextAPI/TextStubV2Tests.cpp b/llvm/unittests/TextAPI/TextStubV2Tests.cpp index a2b4b1a419f405..a4ceb3c2a8b7a4 100644 --- a/llvm/unittests/TextAPI/TextStubV2Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV2Tests.cpp @@ -105,7 +105,7 @@ TEST(TBDv2, ReadFile) { } llvm::sort(Exports); - EXPECT_EQ(sizeof(TBDv2Symbols) / sizeof(ExportedSymbol), Exports.size()); + EXPECT_EQ(std::size(TBDv2Symbols), Exports.size()); EXPECT_TRUE( std::equal(Exports.begin(), Exports.end(), std::begin(TBDv2Symbols))); } diff --git a/llvm/unittests/TextAPI/TextStubV3Tests.cpp b/llvm/unittests/TextAPI/TextStubV3Tests.cpp index 1a42e5440d7431..10e8ab41dd323e 100644 --- a/llvm/unittests/TextAPI/TextStubV3Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV3Tests.cpp @@ -113,7 +113,7 @@ TEST(TBDv3, ReadFile) { } llvm::sort(Exports); - EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size()); + EXPECT_EQ(std::size(TBDv3Symbols), Exports.size()); EXPECT_TRUE( std::equal(Exports.begin(), Exports.end(), std::begin(TBDv3Symbols))); } @@ -205,7 +205,7 @@ TEST(TBDv3, ReadMultipleDocuments) { } llvm::sort(Exports); - EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size()); + EXPECT_EQ(std::size(TBDv3Symbols), Exports.size()); EXPECT_TRUE( std::equal(Exports.begin(), Exports.end(), std::begin(TBDv3Symbols))); diff --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp index 641f95ff10f293..f2327ca85d687a 100644 --- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp @@ -143,12 +143,9 @@ TEST(TBDv4, ReadFile) { {SymbolKind::GlobalSymbol, "_symD", false, false}, }; - EXPECT_EQ(sizeof(ExpectedExportedSymbols) / sizeof(ExportedSymbol), - Exports.size()); - EXPECT_EQ(sizeof(ExpectedReexportedSymbols) / sizeof(ExportedSymbol), - Reexports.size()); - EXPECT_EQ(sizeof(ExpectedUndefinedSymbols) / sizeof(ExportedSymbol), - Undefineds.size()); + EXPECT_EQ(std::size(ExpectedExportedSymbols), Exports.size()); + EXPECT_EQ(std::size(ExpectedReexportedSymbols), Reexports.size()); + EXPECT_EQ(std::size(ExpectedUndefinedSymbols), Undefineds.size()); EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(), std::begin(ExpectedExportedSymbols))); EXPECT_TRUE(std::equal(Reexports.begin(), Reexports.end(), @@ -313,12 +310,9 @@ TEST(TBDv4, ReadMultipleDocuments) { {SymbolKind::GlobalSymbol, "_symD", false, false}, }; - EXPECT_EQ(sizeof(ExpectedExportedSymbols) / sizeof(ExportedSymbol), - Exports.size()); - EXPECT_EQ(sizeof(ExpectedReexportedSymbols) / sizeof(ExportedSymbol), - Reexports.size()); - EXPECT_EQ(sizeof(ExpectedUndefinedSymbols) / sizeof(ExportedSymbol), - Undefineds.size()); + EXPECT_EQ(std::size(ExpectedExportedSymbols), Exports.size()); + EXPECT_EQ(std::size(ExpectedReexportedSymbols), Reexports.size()); + EXPECT_EQ(std::size(ExpectedUndefinedSymbols), Undefineds.size()); EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(), std::begin(ExpectedExportedSymbols))); EXPECT_TRUE(std::equal(Reexports.begin(), Reexports.end(),