[PATCH] D26773: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator

Dominic Chen via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 18 13:17:04 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL287380: [analyzer] Refactor recursive symbol reachability check to use symbol_iterator (authored by ddcc).

Changed prior to commit:
  https://reviews.llvm.org/D26773?vs=78392&id=78575#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26773

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -824,8 +824,9 @@
 }
 
 /// \class ScanReachableSymbols
-/// A Utility class that allows to visit the reachable symbols using a custom
-/// SymbolVisitor.
+/// A utility class that visits the reachable symbols using a custom
+/// SymbolVisitor. Terminates recursive traversal when the visitor function
+/// returns false.
 class ScanReachableSymbols {
   typedef llvm::DenseSet<const void*> VisitedItems;
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -527,32 +527,17 @@
 }
 
 bool ScanReachableSymbols::scan(const SymExpr *sym) {
-  bool wasVisited = !visited.insert(sym).second;
-  if (wasVisited)
-    return true;
-
-  if (!visitor.VisitSymbol(sym))
-    return false;
+  for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
+                                SE = sym->symbol_end();
+       SI != SE; ++SI) {
+    bool wasVisited = !visited.insert(*SI).second;
+    if (wasVisited)
+      continue;
 
-  // TODO: should be rewritten using SymExpr::symbol_iterator.
-  switch (sym->getKind()) {
-    case SymExpr::SymbolRegionValueKind:
-    case SymExpr::SymbolConjuredKind:
-    case SymExpr::SymbolDerivedKind:
-    case SymExpr::SymbolExtentKind:
-    case SymExpr::SymbolMetadataKind:
-      break;
-    case SymExpr::SymbolCastKind:
-      return scan(cast<SymbolCast>(sym)->getOperand());
-    case SymExpr::SymIntExprKind:
-      return scan(cast<SymIntExpr>(sym)->getLHS());
-    case SymExpr::IntSymExprKind:
-      return scan(cast<IntSymExpr>(sym)->getRHS());
-    case SymExpr::SymSymExprKind: {
-      const SymSymExpr *x = cast<SymSymExpr>(sym);
-      return scan(x->getLHS()) && scan(x->getRHS());
-    }
+    if (!visitor.VisitSymbol(*SI))
+      return false;
   }
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26773.78575.patch
Type: text/x-patch
Size: 2210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161118/e8d52e18/attachment.bin>


More information about the cfe-commits mailing list