20 #include "llvm/ADT/SmallPtrSet.h"
23 using namespace clang;
26 #define VARDECL_SET_SIZE 256
27 typedef llvm::SmallPtrSet<const VarDecl*, VARDECL_SET_SIZE>
VarDeclSet;
30 DeclBody(DeclBody), Analyzed(
false) {
53 return !NonConstants->count(VD);
65 return UsedVars->count(VD);
69 const Decl *PseudoConstantAnalysis::getDecl(
const Expr *E) {
70 if (
const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E))
77 std::deque<const Stmt *> WorkList;
82 WorkList.push_back(DeclBody);
84 while (!WorkList.empty()) {
85 const Stmt *Head = WorkList.front();
88 if (
const Expr *Ex = dyn_cast<Expr>(Head))
89 Head = Ex->IgnoreParenCasts();
91 switch (Head->getStmtClass()) {
93 case Stmt::BinaryOperatorClass: {
110 if (LHSDecl == RHSDecl)
127 NonConstants->insert(VD);
138 case Stmt::UnaryOperatorClass: {
160 NonConstants->insert(VD);
171 case Stmt::DeclStmtClass: {
172 const DeclStmt *DS = cast<DeclStmt>(Head);
174 for (
const auto *I : DS->
decls()) {
191 if (
const VarDecl *RefVD = dyn_cast<VarDecl>(D)) {
192 NonConstants->insert(RefVD);
200 case Stmt::DeclRefExprClass: {
204 UsedVars->insert(VD);
211 case Stmt::BlockExprClass: {
212 const BlockExpr *B = cast<BlockExpr>(Head);
214 WorkList.push_back(B->
getBody());
223 for (
const Stmt *SubStmt : Head->children())
225 WorkList.push_back(SubStmt);
llvm::SmallPtrSet< const VarDecl *, VARDECL_SET_SIZE > VarDeclSet
const Expr * getInit() const
~PseudoConstantAnalysis()
bool isReferenceType() const
const Stmt * getBody() const
A builtin binary operation expression such as "x + y" or "x <= y".
Expr * IgnoreParenCasts() LLVM_READONLY
bool isStaticLocal() const
Expr * getSubExpr() const
PseudoConstantAnalysis(const Stmt *DeclBody)
bool wasReferenced(const VarDecl *VD)
const Type * getTypePtr() const
bool isPseudoConstant(const VarDecl *VD)
Run one or more source code analyses.
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
bool hasLocalStorage() const