diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Analysis/Analyses/PsuedoConstantAnalysis.h | 44 | ||||
-rw-r--r-- | include/clang/Analysis/AnalysisContext.h | 5 |
2 files changed, 48 insertions, 1 deletions
diff --git a/include/clang/Analysis/Analyses/PsuedoConstantAnalysis.h b/include/clang/Analysis/Analyses/PsuedoConstantAnalysis.h new file mode 100644 index 0000000000..080f6c1587 --- /dev/null +++ b/include/clang/Analysis/Analyses/PsuedoConstantAnalysis.h @@ -0,0 +1,44 @@ +//== PsuedoConstantAnalysis.h - Find Psuedo-constants in the AST -*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tracks the usage of variables in a Decl body to see if they are +// never written to, implying that they constant. This is useful in static +// analysis to see if a developer might have intended a variable to be const. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_ANALYSIS_PSUEDOCONSTANTANALYSIS +#define LLVM_CLANG_ANALYSIS_PSUEDOCONSTANTANALYSIS + +#include "clang/AST/Stmt.h" + +// The number of ValueDecls we want to keep track of by default (per-function) +#define VALUEDECL_SET_SIZE 256 + +namespace clang { + +class PsuedoConstantAnalysis { +public: + PsuedoConstantAnalysis(const Stmt *DeclBody) : + DeclBody(DeclBody), Analyzed(false) {} + bool isPsuedoConstant(const ValueDecl *VD); + +private: + void RunAnalysis(); + + // for storing the result of analyzed ValueDecls + llvm::SmallPtrSet<const ValueDecl*, VALUEDECL_SET_SIZE> NonConstants; + + const Stmt *DeclBody; + bool Analyzed; +}; + +} + +#endif diff --git a/include/clang/Analysis/AnalysisContext.h b/include/clang/Analysis/AnalysisContext.h index 2b595b99cb..124a08e073 100644 --- a/include/clang/Analysis/AnalysisContext.h +++ b/include/clang/Analysis/AnalysisContext.h @@ -30,6 +30,7 @@ class CFG; class CFGBlock; class LiveVariables; class ParentMap; +class PsuedoConstantAnalysis; class ImplicitParamDecl; class LocationContextManager; class StackFrameContext; @@ -49,6 +50,7 @@ class AnalysisContext { bool builtCFG, builtCompleteCFG; LiveVariables *liveness; ParentMap *PM; + PsuedoConstantAnalysis *PCA; llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars; llvm::BumpPtrAllocator A; bool UseUnoptimizedCFG; @@ -59,7 +61,7 @@ public: bool addehedges = false) : D(d), TU(tu), cfg(0), completeCFG(0), builtCFG(false), builtCompleteCFG(false), - liveness(0), PM(0), + liveness(0), PM(0), PCA(0), ReferencedBlockVars(0), UseUnoptimizedCFG(useUnoptimizedCFG), AddEHEdges(addehedges) {} @@ -85,6 +87,7 @@ public: CFG *getUnoptimizedCFG(); ParentMap &getParentMap(); + PsuedoConstantAnalysis *getPsuedoConstantAnalysis(); LiveVariables *getLiveVariables(); typedef const VarDecl * const * referenced_decls_iterator; |