]> granicus.if.org Git - clang/commitdiff
[analyzer][UninitializedObjectChecker] Refactoring p3.: printTail moved out from...
authorKristof Umann <dkszelethus@gmail.com>
Mon, 13 Aug 2018 18:22:22 +0000 (18:22 +0000)
committerKristof Umann <dkszelethus@gmail.com>
Mon, 13 Aug 2018 18:22:22 +0000 (18:22 +0000)
This is a standalone part of the effort to reduce FieldChainInfos inteerface.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339596 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

index 2aaf11af9c2f9149fc2c1e69d14ca44817d88abf..15faf4bfa547465c06540f23e142bc000b0bd0a3 100644 (file)
@@ -35,6 +35,7 @@ namespace ento {
 /// constructor calls.
 class FieldChainInfo {
 public:
+  using FieldChainImpl = llvm::ImmutableListImpl<const FieldRegion *>;
   using FieldChain = llvm::ImmutableList<const FieldRegion *>;
 
 private:
@@ -48,7 +49,8 @@ public:
   FieldChainInfo(FieldChain::Factory &F) : Factory(F) {}
 
   FieldChainInfo(const FieldChainInfo &Other, const bool IsDereferenced)
-      : Factory(Other.Factory), Chain(Other.Chain), IsDereferenced(IsDereferenced) {}
+      : Factory(Other.Factory), Chain(Other.Chain),
+        IsDereferenced(IsDereferenced) {}
 
   FieldChainInfo(const FieldChainInfo &Other, const FieldRegion *FR,
                  const bool IsDereferenced = false);
@@ -64,12 +66,6 @@ public:
   void print(llvm::raw_ostream &Out) const;
 
 private:
-  /// Prints every element except the last to `Out`. Since ImmutableLists store
-  /// elements in reverse order, and have no reverse iterators, we use a
-  /// recursive function to print the fieldchain correctly. The last element in
-  /// the chain is to be printed by `print`.
-  static void printTail(llvm::raw_ostream &Out,
-                        const llvm::ImmutableListImpl<const FieldRegion *> *L);
   friend struct FieldChainInfoComparator;
 };
 
index c54aff41f57835f7aab182813aa4caeda3b37e4a..ad1a89e71bfb121a012b8b9dce5515568a90d249 100644 (file)
@@ -46,8 +46,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "UninitializedObject.h"
 #include "ClangSACheckers.h"
+#include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@@ -87,7 +87,7 @@ getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context);
 /// (e.g. if the object is a field of another object, in which case we'd check
 /// it multiple times).
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
-                               CheckerContext &Context);
+                                      CheckerContext &Context);
 
 /// Constructs a note message for a given FieldChainInfo object.
 static void printNoteMessage(llvm::raw_ostream &Out,
@@ -346,6 +346,13 @@ const FieldDecl *FieldChainInfo::getEndOfChain() const {
   return (*Chain.begin())->getDecl();
 }
 
+/// Prints every element except the last to `Out`. Since ImmutableLists store
+/// elements in reverse order, and have no reverse iterators, we use a
+/// recursive function to print the fieldchain correctly. The last element in
+/// the chain is to be printed by `print`.
+static void printTail(llvm::raw_ostream &Out,
+                      const FieldChainInfo::FieldChainImpl *L);
+
 // TODO: This function constructs an incorrect string if a void pointer is a
 // part of the chain:
 //
@@ -383,15 +390,13 @@ void FieldChainInfo::print(llvm::raw_ostream &Out) const {
   if (Chain.isEmpty())
     return;
 
-  const llvm::ImmutableListImpl<const FieldRegion *> *L =
-      Chain.getInternalPointer();
+  const FieldChainImpl *L = Chain.getInternalPointer();
   printTail(Out, L->getTail());
   Out << getVariableName(L->getHead()->getDecl());
 }
 
-void FieldChainInfo::printTail(
-    llvm::raw_ostream &Out,
-    const llvm::ImmutableListImpl<const FieldRegion *> *L) {
+static void printTail(llvm::raw_ostream &Out,
+                      const FieldChainInfo::FieldChainImpl *L) {
   if (!L)
     return;
 
@@ -420,7 +425,7 @@ getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context) {
 }
 
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
-                               CheckerContext &Context) {
+                                      CheckerContext &Context) {
 
   Optional<nonloc::LazyCompoundVal> CurrentObject = getObjectVal(Ctor, Context);
   if (!CurrentObject)
index 3c3c256ad9fdc58bc6a4048d1aa6f6687e8e70c6..90d2ff00510ecb742a282ae18ae3a2622702163a 100644 (file)
@@ -18,8 +18,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "UninitializedObject.h"
 #include "ClangSACheckers.h"
+#include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"