]> granicus.if.org Git - clang/commitdiff
Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]).
authorCraig Topper <craig.topper@gmail.com>
Mon, 15 Jul 2013 03:38:40 +0000 (03:38 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 15 Jul 2013 03:38:40 +0000 (03:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186300 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/CommentCommandTraits.cpp
lib/Basic/DiagnosticIDs.cpp
lib/CodeGen/CGRTTI.cpp
lib/Driver/CC1AsOptions.cpp
lib/Driver/DriverOptions.cpp
lib/Driver/Types.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/TreeTransform.h

index 6baf4a9dc6b14e30b3da3b1582f3f31fe05d5669..01bd12e5fefa503fe0c97be582dcbe7e91e8957c 100644 (file)
@@ -75,7 +75,7 @@ CommandTraits::getTypoCorrectCommandInfo(StringRef Typo) const {
   
   SmallVector<const CommandInfo *, 2> BestCommand;
   
-  int NumOfCommands = sizeof(Commands) / sizeof(CommandInfo);
+  const int NumOfCommands = llvm::array_lengthof(Commands);
   for (int i = 0; i < NumOfCommands; i++)
     HelperTypoCorrectCommandInfo(BestCommand, Typo, &Commands[i]);
   
index 353af4bd6df1910428af49077efd9c98dc1392a9..c2cb366e5e03e2bcfa1848d93b895ead3d5892d5 100644 (file)
@@ -15,6 +15,7 @@
 #include "clang/Basic/AllDiagnostics.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <map>
@@ -86,7 +87,7 @@ static const StaticDiagInfoRec StaticDiagInfo[] = {
 };
 
 static const unsigned StaticDiagInfoSize =
-  sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
+  llvm::array_lengthof(StaticDiagInfo)-1;
 
 /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
 /// or null if the ID is invalid.
@@ -224,7 +225,7 @@ static const StaticDiagCategoryRec CategoryNameTable[] = {
 
 /// getNumberOfCategories - Return the number of categories
 unsigned DiagnosticIDs::getNumberOfCategories() {
-  return sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
+  return llvm::array_lengthof(CategoryNameTable) - 1;
 }
 
 /// getCategoryNameFromID - Given a category ID, return the name of the
@@ -528,8 +529,7 @@ static const WarningOption OptionTable[] = {
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef GET_DIAG_TABLE
 };
-static const size_t OptionTableSize =
-sizeof(OptionTable) / sizeof(OptionTable[0]);
+static const size_t OptionTableSize = llvm::array_lengthof(OptionTable);
 
 static bool WarningOptionCompare(const WarningOption &LHS,
                                  const WarningOption &RHS) {
index 23e8e452fe2522a731aac39292a8f3322244d9f7..72d4220789e17084d94c1365e1642b7b10a4c70d 100644 (file)
@@ -972,6 +972,6 @@ void CodeGenModule::EmitFundamentalRTTIDescriptors() {
                                   Context.UnsignedLongLongTy, Context.FloatTy,
                                   Context.DoubleTy, Context.LongDoubleTy,
                                   Context.Char16Ty, Context.Char32Ty };
-  for (unsigned i = 0; i < sizeof(FundamentalTypes)/sizeof(QualType); ++i)
+  for (unsigned i = 0; i < llvm::array_lengthof(FundamentalTypes); ++i)
     EmitFundamentalRTTIDescriptor(FundamentalTypes[i]);
 }
index b1e0deae3934d6c6995efe3ce18f015c6dd72a94..62c3afbb36c58d7e1cc0bfde4368b00fde4ecfd5 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Driver/CC1AsOptions.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 using namespace clang;
@@ -36,8 +37,7 @@ namespace {
 class CC1AsOptTable : public OptTable {
 public:
   CC1AsOptTable()
-    : OptTable(CC1AsInfoTable,
-               sizeof(CC1AsInfoTable) / sizeof(CC1AsInfoTable[0])) {}
+    : OptTable(CC1AsInfoTable, llvm::array_lengthof(CC1AsInfoTable)) {}
 };
 
 }
index 0bf7303aca72664d4181b6f93222a34ff0577bcf..39787350cf0c71c9fd4702260b39d684d3ac2ed0 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 
@@ -36,7 +37,7 @@ namespace {
 class DriverOptTable : public OptTable {
 public:
   DriverOptTable()
-    : OptTable(InfoTable, sizeof(InfoTable) / sizeof(InfoTable[0])) {}
+    : OptTable(InfoTable, llvm::array_lengthof(InfoTable)) {}
 };
 
 }
index 87c695f1331a1ee3e3c3ba2fb34a1618af7d9fef..19870fe6fdad46d8ec1fc9299e43611ba0e17784 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Driver/Types.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include <cassert>
 #include <string.h>
@@ -28,7 +29,7 @@ static const TypeInfo TypeInfos[] = {
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
-static const unsigned numTypes = sizeof(TypeInfos) / sizeof(TypeInfos[0]);
+static const unsigned numTypes = llvm::array_lengthof(TypeInfos);
 
 static const TypeInfo &getInfo(unsigned id) {
   assert(id > 0 && id - 1 < numTypes && "Invalid Type ID.");
index be336277b4a5538827c507c798c7947fc48eb317..cd3968d8b11d6d5d6f5ff329019b00017a98d4e9 100644 (file)
@@ -3624,7 +3624,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       "extern", "inline", "static", "typedef"
     };
 
-    const unsigned NumCTypeSpecs = sizeof(CTypeSpecs) / sizeof(CTypeSpecs[0]);
+    const unsigned NumCTypeSpecs = llvm::array_lengthof(CTypeSpecs);
     for (unsigned I = 0; I != NumCTypeSpecs; ++I)
       Consumer.addKeywordResult(CTypeSpecs[I]);
 
@@ -3671,7 +3671,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       const char *CXXExprs[] = {
         "delete", "new", "operator", "throw", "typeid"
       };
-      const unsigned NumCXXExprs = sizeof(CXXExprs) / sizeof(CXXExprs[0]);
+      const unsigned NumCXXExprs = llvm::array_lengthof(CXXExprs);
       for (unsigned I = 0; I != NumCXXExprs; ++I)
         Consumer.addKeywordResult(CXXExprs[I]);
 
@@ -3697,7 +3697,7 @@ static void AddKeywordsToConsumer(Sema &SemaRef,
       // Statements.
       const char *CStmts[] = {
         "do", "else", "for", "goto", "if", "return", "switch", "while" };
-      const unsigned NumCStmts = sizeof(CStmts) / sizeof(CStmts[0]);
+      const unsigned NumCStmts = llvm::array_lengthof(CStmts);
       for (unsigned I = 0; I != NumCStmts; ++I)
         Consumer.addKeywordResult(CStmts[I]);
 
index aaeedc10420372c806022fe350c0a672363e418c..5b4716f5be2e0497a20f70e9321f46935721eef5 100644 (file)
@@ -9126,7 +9126,7 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
     SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
     SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
   };
-  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
+  const unsigned NumTypes = llvm::array_lengthof(Types);
   QualType SizeType;
   for (unsigned I = 0; I != NumTypes; ++I)
     if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {