From 5c23e27ba19c566b114f8a89a856f1d08238fa96 Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Wed, 5 Jul 2023 08:56:13 +0200 Subject: [analyzer][NFC] Move away from using raw-for loops inside StaticAnalyzer I'm involved with the Static Analyzer for the most part. I think we should embrace newer language standard features and gradually move forward. Differential Revision: https://reviews.llvm.org/D154325 --- .../StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp') diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp index 57d3c99..0228e82 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -49,6 +49,7 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h" #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" @@ -941,11 +942,9 @@ void StdLibraryFunctionsChecker::RangeConstraint::applyOnWithinRange( if (Ranges.empty()) return; - const IntRangeVector &R = getRanges(); - size_t E = R.size(); - for (size_t I = 0; I != E; ++I) { - const llvm::APSInt &Min = BVF.getValue(R[I].first, ArgT); - const llvm::APSInt &Max = BVF.getValue(R[I].second, ArgT); + for (auto [Start, End] : getRanges()) { + const llvm::APSInt &Min = BVF.getValue(Start, ArgT); + const llvm::APSInt &Max = BVF.getValue(End, ArgT); assert(Min <= Max); if (!F(Min, Max)) return; @@ -1376,12 +1375,11 @@ bool StdLibraryFunctionsChecker::Signature::matches( } // Check the argument types. - for (size_t I = 0, E = ArgTys.size(); I != E; ++I) { - QualType ArgTy = ArgTys[I]; + for (auto [Idx, ArgTy] : llvm::enumerate(ArgTys)) { if (isIrrelevant(ArgTy)) continue; QualType FDArgTy = - RemoveRestrict(FD->getParamDecl(I)->getType().getCanonicalType()); + RemoveRestrict(FD->getParamDecl(Idx)->getType().getCanonicalType()); if (ArgTy != FDArgTy) return false; } -- cgit v1.1