[llvm] r186301 - Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]).
Kai Nacke
kai.nacke at redstar.de
Mon Jul 15 00:13:34 PDT 2013
Hi Craig!
The windows build with VS2012 results in:
d:\opensource\llvm\llvm-git\lib\support\Windows/Path.inc(591): error
C3861: 'array_lengthof': identifier not found
[D:\OpenSource\LLVM\build-x64-git\lib\Support\LLVMSupport.vcxproj]
Regards
Kai
On 15.07.2013 06:27, Craig Topper wrote:
> Author: ctopper
> Date: Sun Jul 14 23:27:47 2013
> New Revision: 186301
>
> URL: http://llvm.org/viewvc/llvm-project?rev=186301&view=rev
> Log:
> Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]).
>
> Modified:
> llvm/trunk/lib/MC/MCAsmBackend.cpp
> llvm/trunk/lib/Support/Unix/Signals.inc
> llvm/trunk/lib/Support/Windows/Path.inc
> llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
> llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
> llvm/trunk/lib/Target/R600/AMDGPUISelLowering.cpp
> llvm/trunk/lib/Target/R600/AMDILISelLowering.cpp
> llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
>
> Modified: llvm/trunk/lib/MC/MCAsmBackend.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmBackend.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCAsmBackend.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmBackend.cpp Sun Jul 14 23:27:47 2013
> @@ -8,6 +8,7 @@
> //===----------------------------------------------------------------------===//
>
> #include "llvm/MC/MCAsmBackend.h"
> +#include "llvm/ADT/STLExtras.h"
> #include "llvm/MC/MCFixupKindInfo.h"
> using namespace llvm;
>
> @@ -37,7 +38,6 @@ MCAsmBackend::getFixupKindInfo(MCFixupKi
> { "FK_SecRel_8", 0, 64, 0 }
> };
>
> - assert((size_t)Kind <= sizeof(Builtins) / sizeof(Builtins[0]) &&
> - "Unknown fixup kind");
> + assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
> return Builtins[Kind];
> }
>
> Modified: llvm/trunk/lib/Support/Unix/Signals.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Signals.inc?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Unix/Signals.inc (original)
> +++ llvm/trunk/lib/Support/Unix/Signals.inc Sun Jul 14 23:27:47 2013
> @@ -55,8 +55,7 @@ static std::vector<std::pair<void(*)(voi
> static const int IntSigs[] = {
> SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
> };
> -static const int *const IntSigsEnd =
> - IntSigs + sizeof(IntSigs) / sizeof(IntSigs[0]);
> +static const int *const IntSigsEnd = array_endof(IntSigs);
>
> // KillSigs - Signals that represent that we have a bug, and our prompt
> // termination has been ordered.
> @@ -75,8 +74,7 @@ static const int KillSigs[] = {
> , SIGEMT
> #endif
> };
> -static const int *const KillSigsEnd =
> - KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
> +static const int *const KillSigsEnd = array_endof(KillSigs);
>
> static unsigned NumRegisteredSignals = 0;
> static struct {
> @@ -86,8 +84,7 @@ static struct {
>
>
> static void RegisterHandler(int Signal) {
> - assert(NumRegisteredSignals <
> - sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) &&
> + assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) &&
> "Out of space for signal handlers!");
>
> struct sigaction NewHandler;
>
> Modified: llvm/trunk/lib/Support/Windows/Path.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Windows/Path.inc (original)
> +++ llvm/trunk/lib/Support/Windows/Path.inc Sun Jul 14 23:27:47 2013
> @@ -588,7 +588,7 @@ static bool isReservedName(StringRef pat
> return true;
>
> // Then compare against the list of ancient reserved names
> - for (size_t i = 0; i < sizeof(sReservedNames) / sizeof(const char *); ++i) {
> + for (size_t i = 0; i < array_lengthof(sReservedNames); ++i) {
> if (path.equals_lower(sReservedNames[i]))
> return true;
> }
>
> Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Sun Jul 14 23:27:47 2013
> @@ -2732,7 +2732,7 @@ ARMTargetLowering::StoreByValRegs(CCStat
> lastRegToSaveIndex = REnd - ARM::R0;
> } else {
> firstRegToSaveIndex = CCInfo.getFirstUnallocated
> - (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0]));
> + (GPRArgRegs, array_lengthof(GPRArgRegs));
> lastRegToSaveIndex = 4;
> }
>
>
> Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Sun Jul 14 23:27:47 2013
> @@ -853,7 +853,7 @@ void PPCDarwinAsmPrinter::EmitStartOfAsm
>
> // FIXME: This is a total hack, finish mc'izing the PPC backend.
> if (OutStreamer.hasRawTextSupport()) {
> - assert(Directive < sizeof(CPUDirectives) / sizeof(*CPUDirectives) &&
> + assert(Directive < array_lengthof(CPUDirectives) &&
> "CPUDirectives[] might not be up-to-date!");
> OutStreamer.EmitRawText("\t.machine " + Twine(CPUDirectives[Directive]));
> }
>
> Modified: llvm/trunk/lib/Target/R600/AMDGPUISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUISelLowering.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/R600/AMDGPUISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/R600/AMDGPUISelLowering.cpp Sun Jul 14 23:27:47 2013
> @@ -82,7 +82,7 @@ AMDGPUTargetLowering::AMDGPUTargetLoweri
> (int)MVT::v2i32,
> (int)MVT::v4i32
> };
> - size_t NumTypes = sizeof(types) / sizeof(*types);
> + const size_t NumTypes = array_lengthof(types);
>
> for (unsigned int x = 0; x < NumTypes; ++x) {
> MVT::SimpleValueType VT = (MVT::SimpleValueType)types[x];
>
> Modified: llvm/trunk/lib/Target/R600/AMDILISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDILISelLowering.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/R600/AMDILISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/R600/AMDILISelLowering.cpp Sun Jul 14 23:27:47 2013
> @@ -82,10 +82,10 @@ void AMDGPUTargetLowering::InitAMDILLowe
> (int)MVT::v2f64,
> (int)MVT::v2i64
> };
> - size_t NumTypes = sizeof(types) / sizeof(*types);
> - size_t NumFloatTypes = sizeof(FloatTypes) / sizeof(*FloatTypes);
> - size_t NumIntTypes = sizeof(IntTypes) / sizeof(*IntTypes);
> - size_t NumVectorTypes = sizeof(VectorTypes) / sizeof(*VectorTypes);
> + const size_t NumTypes = array_lengthof(types);
> + const size_t NumFloatTypes = array_lengthof(FloatTypes);
> + const size_t NumIntTypes = array_lengthof(IntTypes);
> + const size_t NumVectorTypes = array_lengthof(VectorTypes);
>
> const AMDGPUSubtarget &STM = getTargetMachine().getSubtarget<AMDGPUSubtarget>();
> // These are the current register classes that are
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=186301&r1=186300&r2=186301&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Sun Jul 14 23:27:47 2013
> @@ -12,6 +12,7 @@
> //===----------------------------------------------------------------------===//
>
> #include "InstCombine.h"
> +#include "llvm/ADT/STLExtras.h"
> #include "llvm/Analysis/InstructionSimplify.h"
> #include "llvm/IR/DataLayout.h"
> #include "llvm/Support/GetElementPtrTypeIterator.h"
> @@ -659,7 +660,7 @@ Value *FAddCombine::simplifyFAdd(AddendV
> }
> }
>
> - assert((NextTmpIdx <= sizeof(TmpResult)/sizeof(TmpResult[0]) + 1) &&
> + assert((NextTmpIdx <= array_lengthof(TmpResult) + 1) &&
> "out-of-bound access");
>
> if (ConstAdd)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list