[clang] 70d592d - [Analyzer] Use a reference in a range-based for

Mark de Wever via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 21 05:52:48 PST 2019


Author: Mark de Wever
Date: 2019-12-21T14:52:29+01:00
New Revision: 70d592d68c7a8666183308d1daa2322ede87df09

URL: https://github.com/llvm/llvm-project/commit/70d592d68c7a8666183308d1daa2322ede87df09
DIFF: https://github.com/llvm/llvm-project/commit/70d592d68c7a8666183308d1daa2322ede87df09.diff

LOG: [Analyzer] Use a reference in a range-based for

This avoids unneeded copies when using a range-based for loops.

This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

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

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
    clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
    clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
index b0d101c88517..dd89c53478e8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -62,7 +62,7 @@ class InnerPointerChecker
     // lookup by region.
     bool isSymbolTracked(ProgramStateRef State, SymbolRef Sym) {
       RawPtrMapTy Map = State->get<RawPtrMap>();
-      for (const auto Entry : Map) {
+      for (const auto &Entry : Map) {
         if (Entry.second.contains(Sym))
           return true;
       }
@@ -236,7 +236,7 @@ void InnerPointerChecker::checkDeadSymbols(SymbolReaper &SymReaper,
   ProgramStateRef State = C.getState();
   PtrSet::Factory &F = State->getStateManager().get_context<PtrSet>();
   RawPtrMapTy RPM = State->get<RawPtrMap>();
-  for (const auto Entry : RPM) {
+  for (const auto &Entry : RPM) {
     if (!SymReaper.isLiveRegion(Entry.first)) {
       // Due to incomplete destructor support, some dead regions might
       // remain in the program state map. Clean them up.
@@ -266,7 +266,7 @@ std::unique_ptr<BugReporterVisitor> getInnerPointerBRVisitor(SymbolRef Sym) {
 
 const MemRegion *getContainerObjRegion(ProgramStateRef State, SymbolRef Sym) {
   RawPtrMapTy Map = State->get<RawPtrMap>();
-  for (const auto Entry : Map) {
+  for (const auto &Entry : Map) {
     if (Entry.second.contains(Sym)) {
       return Entry.first;
     }

diff  --git a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
index ab4e8112d677..f47776c711ad 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
@@ -429,7 +429,7 @@ void IteratorModeling::checkLiveSymbols(ProgramStateRef State,
   // Keep symbolic expressions of iterator positions, container begins and ends
   // alive
   auto RegionMap = State->get<IteratorRegionMap>();
-  for (const auto Reg : RegionMap) {
+  for (const auto &Reg : RegionMap) {
     const auto Offset = Reg.second.getOffset();
     for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
       if (isa<SymbolData>(*i))
@@ -437,7 +437,7 @@ void IteratorModeling::checkLiveSymbols(ProgramStateRef State,
   }
 
   auto SymbolMap = State->get<IteratorSymbolMap>();
-  for (const auto Sym : SymbolMap) {
+  for (const auto &Sym : SymbolMap) {
     const auto Offset = Sym.second.getOffset();
     for (auto i = Offset->symbol_begin(); i != Offset->symbol_end(); ++i)
       if (isa<SymbolData>(*i))
@@ -445,7 +445,7 @@ void IteratorModeling::checkLiveSymbols(ProgramStateRef State,
   }
 
   auto ContMap = State->get<ContainerMap>();
-  for (const auto Cont : ContMap) {
+  for (const auto &Cont : ContMap) {
     const auto CData = Cont.second;
     if (CData.getBegin()) {
       SR.markLive(CData.getBegin());
@@ -466,7 +466,7 @@ void IteratorModeling::checkDeadSymbols(SymbolReaper &SR,
   auto State = C.getState();
 
   auto RegionMap = State->get<IteratorRegionMap>();
-  for (const auto Reg : RegionMap) {
+  for (const auto &Reg : RegionMap) {
     if (!SR.isLiveRegion(Reg.first)) {
       // The region behind the `LazyCompoundVal` is often cleaned up before
       // the `LazyCompoundVal` itself. If there are iterator positions keyed
@@ -478,14 +478,14 @@ void IteratorModeling::checkDeadSymbols(SymbolReaper &SR,
   }
 
   auto SymbolMap = State->get<IteratorSymbolMap>();
-  for (const auto Sym : SymbolMap) {
+  for (const auto &Sym : SymbolMap) {
     if (!SR.isLive(Sym.first)) {
       State = State->remove<IteratorSymbolMap>(Sym.first);
     }
   }
 
   auto ContMap = State->get<ContainerMap>();
-  for (const auto Cont : ContMap) {
+  for (const auto &Cont : ContMap) {
     if (!SR.isLiveRegion(Cont.first)) {
       // We must keep the container data while it has live iterators to be able
       // to compare them to the begin and the end of the container.
@@ -1456,13 +1456,13 @@ ProgramStateRef relateSymbols(ProgramStateRef State, SymbolRef Sym1,
 
 bool hasLiveIterators(ProgramStateRef State, const MemRegion *Cont) {
   auto RegionMap = State->get<IteratorRegionMap>();
-  for (const auto Reg : RegionMap) {
+  for (const auto &Reg : RegionMap) {
     if (Reg.second.getContainer() == Cont)
       return true;
   }
 
   auto SymbolMap = State->get<IteratorSymbolMap>();
-  for (const auto Sym : SymbolMap) {
+  for (const auto &Sym : SymbolMap) {
     if (Sym.second.getContainer() == Cont)
       return true;
   }
@@ -1472,7 +1472,7 @@ bool hasLiveIterators(ProgramStateRef State, const MemRegion *Cont) {
 
 bool isBoundThroughLazyCompoundVal(const Environment &Env,
                                    const MemRegion *Reg) {
-  for (const auto Binding: Env) {
+  for (const auto &Binding : Env) {
     if (const auto LCVal = Binding.second.getAs<nonloc::LazyCompoundVal>()) {
       if (LCVal->getRegion() == Reg)
         return true;
@@ -1488,7 +1488,7 @@ ProgramStateRef processIteratorPositions(ProgramStateRef State, Condition Cond,
   auto &RegionMapFactory = State->get_context<IteratorRegionMap>();
   auto RegionMap = State->get<IteratorRegionMap>();
   bool Changed = false;
-  for (const auto Reg : RegionMap) {
+  for (const auto &Reg : RegionMap) {
     if (Cond(Reg.second)) {
       RegionMap = RegionMapFactory.add(RegionMap, Reg.first, Proc(Reg.second));
       Changed = true;
@@ -1501,7 +1501,7 @@ ProgramStateRef processIteratorPositions(ProgramStateRef State, Condition Cond,
   auto &SymbolMapFactory = State->get_context<IteratorSymbolMap>();
   auto SymbolMap = State->get<IteratorSymbolMap>();
   Changed = false;
-  for (const auto Sym : SymbolMap) {
+  for (const auto &Sym : SymbolMap) {
     if (Cond(Sym.second)) {
       SymbolMap = SymbolMapFactory.add(SymbolMap, Sym.first, Proc(Sym.second));
       Changed = true;

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 16047055862e..0525b5c41e34 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -505,7 +505,7 @@ NoStoreFuncVisitor::findRegionOfInterestInRecord(
   // Recursively examine the base classes.
   // Note that following base classes does not increase the recursion depth.
   if (const auto *RDX = dyn_cast<CXXRecordDecl>(RD))
-    for (const auto II : RDX->bases())
+    for (const auto &II : RDX->bases())
       if (const RecordDecl *RRD = II.getType()->getAsRecordDecl())
         if (Optional<RegionVector> Out =
                 findRegionOfInterestInRecord(RRD, State, R, Vec, depth))


        


More information about the cfe-commits mailing list