diff options
author | Craig Topper <craig.topper@gmail.com> | 2013-07-15 03:38:40 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2013-07-15 03:38:40 +0000 |
commit | b960232518a1cd79c5f64ab5ef54c88e34660191 (patch) | |
tree | 7f94ec980cc97100437556bbf15be79bf6827d81 | |
parent | 0f855a9c2517fc80803ab81a4aa0bb015918cf21 (diff) | |
download | flang-b960232518a1cd79c5f64ab5ef54c88e34660191.tar.gz |
Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186300 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/CommentCommandTraits.cpp | 2 | ||||
-rw-r--r-- | lib/Basic/DiagnosticIDs.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGRTTI.cpp | 2 | ||||
-rw-r--r-- | lib/Driver/CC1AsOptions.cpp | 4 | ||||
-rw-r--r-- | lib/Driver/DriverOptions.cpp | 3 | ||||
-rw-r--r-- | lib/Driver/Types.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 2 |
8 files changed, 16 insertions, 14 deletions
diff --git a/lib/AST/CommentCommandTraits.cpp b/lib/AST/CommentCommandTraits.cpp index 6baf4a9dc6..01bd12e5fe 100644 --- a/lib/AST/CommentCommandTraits.cpp +++ b/lib/AST/CommentCommandTraits.cpp @@ -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]); diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index 353af4bd6d..c2cb366e5e 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -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) { diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp index 23e8e452fe..72d4220789 100644 --- a/lib/CodeGen/CGRTTI.cpp +++ b/lib/CodeGen/CGRTTI.cpp @@ -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]); } diff --git a/lib/Driver/CC1AsOptions.cpp b/lib/Driver/CC1AsOptions.cpp index b1e0deae39..62c3afbb36 100644 --- a/lib/Driver/CC1AsOptions.cpp +++ b/lib/Driver/CC1AsOptions.cpp @@ -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)) {} }; } diff --git a/lib/Driver/DriverOptions.cpp b/lib/Driver/DriverOptions.cpp index 0bf7303aca..39787350cf 100644 --- a/lib/Driver/DriverOptions.cpp +++ b/lib/Driver/DriverOptions.cpp @@ -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)) {} }; } diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp index 87c695f133..19870fe6fd 100644 --- a/lib/Driver/Types.cpp +++ b/lib/Driver/Types.cpp @@ -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."); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index be336277b4..cd3968d8b1 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -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]); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index aaeedc1042..5b4716f5be 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -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])) { |