[lld] 1173ecf - [lld] Use std::size instead of llvm::array_lengthof

Joe Loser via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 14:29:48 PDT 2022


Author: Joe Loser
Date: 2022-09-09T15:28:30-06:00
New Revision: 1173ecf9fbc7140339322900747796fe2bca36f0

URL: https://github.com/llvm/llvm-project/commit/1173ecf9fbc7140339322900747796fe2bca36f0
DIFF: https://github.com/llvm/llvm-project/commit/1173ecf9fbc7140339322900747796fe2bca36f0.diff

LOG: [lld] Use std::size instead of llvm::array_lengthof

LLVM contains a helpful function for getting the size of a C-style
array: `llvm::array_lengthof`. This is useful prior to C++17, but not as
helpful for C++17 or later: `std::size` already has support for C-style
arrays.

Differential Revision: https://reviews.llvm.org/D133598

Added: 
    

Modified: 
    lld/COFF/Chunks.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index a029b01451461..ee222cb6f08da 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -12,14 +12,15 @@
 #include "SymbolTable.h"
 #include "Symbols.h"
 #include "Writer.h"
-#include "llvm/ADT/Twine.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/BinaryFormat/COFF.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
+#include <iterator>
 
 using namespace llvm;
 using namespace llvm::object;
@@ -947,7 +948,7 @@ MergeChunk::MergeChunk(uint32_t alignment)
 void MergeChunk::addSection(COFFLinkerContext &ctx, SectionChunk *c) {
   assert(isPowerOf2_32(c->getAlignment()));
   uint8_t p2Align = llvm::Log2_32(c->getAlignment());
-  assert(p2Align < array_lengthof(ctx.mergeChunkInstances));
+  assert(p2Align < std::size(ctx.mergeChunkInstances));
   auto *&mc = ctx.mergeChunkInstances[p2Align];
   if (!mc)
     mc = make<MergeChunk>(c->getAlignment());


        


More information about the llvm-commits mailing list