[PATCH] D51886: [analyzer][UninitializedObjectChecker] Using the new const methods of ImmutableList

Umann Kristóf via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 10 12:37:04 PDT 2018


Szelethus created this revision.
Szelethus added reviewers: george.karpenkov, NoQ, xazax.hun, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, whisperity.

Clang side changes to https://reviews.llvm.org/D51881. This is an improvement, and won't cause compilation errors if not commited together.


Repository:
  rC Clang

https://reviews.llvm.org/D51886

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp


Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -359,14 +359,6 @@
 //                       Methods for FieldChainInfo.
 //===----------------------------------------------------------------------===//
 
-const FieldRegion *FieldChainInfo::getUninitRegion() const {
-  assert(!Chain.isEmpty() && "Empty fieldchain!");
-
-  // ImmutableList::getHead() isn't a const method, hence the not too nice
-  // implementation.
-  return (*Chain.begin()).getRegion();
-}
-
 bool FieldChainInfo::contains(const FieldRegion *FR) const {
   for (const FieldNode &Node : Chain) {
     if (Node.isSameRegion(FR))
@@ -380,7 +372,7 @@
 /// recursive function to print the fieldchain correctly. The last element in
 /// the chain is to be printed by `FieldChainInfo::print`.
 static void printTail(llvm::raw_ostream &Out,
-                      const FieldChainInfo::FieldChainImpl *L);
+                      const FieldChainInfo::FieldChain L);
 
 // FIXME: This function constructs an incorrect string in the following case:
 //
@@ -399,30 +391,29 @@
   if (Chain.isEmpty())
     return;
 
-  const FieldChainImpl *L = Chain.getInternalPointer();
-  const FieldNode &LastField = L->getHead();
+  const FieldNode &LastField = getHead();
 
   LastField.printNoteMsg(Out);
   Out << '\'';
 
   for (const FieldNode &Node : Chain)
     Node.printPrefix(Out);
 
   Out << "this->";
-  printTail(Out, L->getTail());
+  printTail(Out, Chain.getTail());
   LastField.printNode(Out);
   Out << '\'';
 }
 
 static void printTail(llvm::raw_ostream &Out,
-                      const FieldChainInfo::FieldChainImpl *L) {
-  if (!L)
+                      const FieldChainInfo::FieldChain L) {
+  if (L.isEmpty())
     return;
 
-  printTail(Out, L->getTail());
+  printTail(Out, L.getTail());
 
-  L->getHead().printNode(Out);
-  L->getHead().printSeparator(Out);
+  L.getHead().printNode(Out);
+  L.getHead().printSeparator(Out);
 }
 
 //===----------------------------------------------------------------------===//
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -107,7 +107,6 @@
 /// functions such as add() and replaceHead().
 class FieldChainInfo {
 public:
-  using FieldChainImpl = llvm::ImmutableListImpl<const FieldNode &>;
   using FieldChain = llvm::ImmutableList<const FieldNode &>;
 
 private:
@@ -134,8 +133,8 @@
   bool contains(const FieldRegion *FR) const;
   bool isEmpty() const { return Chain.isEmpty(); }
 
-  const FieldRegion *getUninitRegion() const;
-  const FieldNode &getHead() { return Chain.getHead(); }
+  const FieldNode &getHead() const { return Chain.getHead(); }
+  const FieldRegion *getUninitRegion() const { return getHead().getRegion(); }
 
   void printNoteMsg(llvm::raw_ostream &Out) const;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51886.164726.patch
Type: text/x-patch
Size: 3232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180910/ac9da9cb/attachment-0001.bin>


More information about the cfe-commits mailing list