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 *,
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: {
}
}
+// 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;
+}
// False positive tests
unsigned false1() {
- return (5 - 2 - 3); // no-warning
+ int a = 10;
+ return a * (5 - 2 - 3); // no-warning
}
enum testenum { enum1 = 0, enum2 };
unsigned false2() {
- return enum1; // no-warning
+ int a = 1234;
+ return enum1 + a; // no-warning
}
extern unsigned foo();