//===-- GRConstants.cpp - Simple, Path-Sens. Constant Prop. ------*- C++ -*-==////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// Constant Propagation via Graph Reachability//// This files defines a simple analysis that performs path-sensitive// constant propagation within a function. An example use of this analysis// is to perform simple checks for NULL dereferences.////===----------------------------------------------------------------------===//#include"RValues.h"#include"ValueState.h"#include"clang/Analysis/PathSensitive/GREngine.h"#include"clang/AST/Expr.h"#include"clang/AST/ASTContext.h"#include"clang/Analysis/Analyses/LiveVariables.h"#include"clang/Basic/Diagnostic.h"#include"llvm/Support/Casting.h"#include"llvm/Support/DataTypes.h"#include"llvm/ADT/APSInt.h"#include"llvm/ADT/FoldingSet.h"#include"llvm/ADT/ImmutableMap.h"#include"llvm/ADT/SmallVector.h"#include"llvm/ADT/SmallPtrSet.h"#include"llvm/Support/Allocator.h"#include"llvm/Support/Compiler.h"#include"llvm/Support/Streams.h"#include<functional>#ifndef NDEBUG#include"llvm/Support/GraphWriter.h"#include<sstream>#endifusingnamespaceclang;usingllvm::dyn_cast;usingllvm::cast;usingllvm::APSInt;//===----------------------------------------------------------------------===//// The Checker.//// FIXME: This checker logic should be eventually broken into two components.// The first is the "meta"-level checking logic; the code that// does the Stmt visitation, fetching values from the map, etc.// The second part does the actual state manipulation. This way we// get more of a separate of concerns of these two pieces, with the// latter potentially being refactored back into the main checking// logic.//===----------------------------------------------------------------------===//namespace{classVISIBILITY_HIDDENGRConstants{public:typedefValueStateManager::StateTyStateTy;typedefGRStmtNodeBuilder<GRConstants>StmtNodeBuilder;typedefGRBranchNodeBuilder<GRConstants>BranchNodeBuilder;typedefExplodedGraph<GRConstants>GraphTy;typedefGraphTy::NodeTyNodeTy;classNodeSet{typedefllvm::SmallVector<NodeTy*,3>ImplTy;ImplTyImpl;public:NodeSet(){}NodeSet(NodeTy*N){assert(N&&!N->isSink());Impl.push_back(N);}voidAdd(NodeTy*N){if(N&&!N->isSink())Impl.push_back(N);}typedefImplTy::iteratoriterator;typedefImplTy::const_iteratorconst_iterator;unsignedsize()