Added basic psuedoconstant checking in IdempotentOperationChecker and fixed some test cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111190 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Checker/IdempotentOperationChecker.cpp b/lib/Checker/IdempotentOperationChecker.cpp
index 74f4a62..4f2810e 100644
--- a/lib/Checker/IdempotentOperationChecker.cpp
+++ b/lib/Checker/IdempotentOperationChecker.cpp
@@ -81,6 +81,7 @@
const CFGBlock *CB,
const GRCoreEngine &CE);
static bool CanVary(const Expr *Ex, ASTContext &Ctx);
+ static bool isPseudoConstant(const DeclRefExpr *D);
// Hash table
typedef llvm::DenseMap<const BinaryOperator *,
@@ -530,8 +531,7 @@
return SE->getTypeOfArgument()->isVariableArrayType();
}
case Stmt::DeclRefExprClass:
- // return !IsPseudoConstant(cast<DeclRefExpr>(Ex));
- return true;
+ return !isPseudoConstant(cast<DeclRefExpr>(Ex));
// The next cases require recursion for subexpressions
case Stmt::BinaryOperatorClass: {
@@ -555,3 +555,17 @@
}
}
+// Returns true if a DeclRefExpr behaves like a constant.
+bool IdempotentOperationChecker::isPseudoConstant(const DeclRefExpr *DR) {
+ // Check for an enum
+ if (isa<EnumConstantDecl>(DR->getDecl()))
+ return true;
+
+ // Check for a static variable
+ // FIXME: Analysis should model static vars
+ if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl()))
+ if (VD->isStaticLocal())
+ return true;
+
+ return false;
+}