r274974 - [analyzer] Rewrite manual erase loop using remove_if.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 9 04:16:57 PDT 2016
Author: d0k
Date: Sat Jul 9 06:16:56 2016
New Revision: 274974
URL: http://llvm.org/viewvc/llvm-project?rev=274974&view=rev
Log:
[analyzer] Rewrite manual erase loop using remove_if.
No functionality change intended.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp?rev=274974&r1=274973&r2=274974&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp Sat Jul 9 06:16:56 2016
@@ -146,25 +146,24 @@ private:
const Decl *getDecl(const MemberExpr *ME) { return ME->getMemberDecl(); }
template <typename T1>
- void Erase(const T1 *DR, std::function<bool(theVecType::iterator)> pred) {
- theVecType::iterator i = toScanFor.end();
- theVecType::iterator e = toScanFor.begin();
- while (i != e) {
- --i;
- if (const T1 *DR_i = dyn_cast<T1>(i->variable)) {
- if ((getDecl(DR_i) == getDecl(DR)) && pred(i))
- i = toScanFor.erase(i);
- }
- }
+ void Erase(const T1 *DR,
+ llvm::function_ref<bool(const MallocOverflowCheck &)> Pred =
+ [](const MallocOverflowCheck &) { return true; }) {
+ auto P = [this, DR, Pred](const MallocOverflowCheck &Check) {
+ if (const auto *CheckDR = dyn_cast<T1>(Check.variable))
+ return getDecl(CheckDR) == getDecl(DR) && Pred(Check);
+ return false;
+ };
+ toScanFor.erase(std::remove_if(toScanFor.begin(), toScanFor.end(), P),
+ toScanFor.end());
}
void CheckExpr(const Expr *E_p) {
- auto PredTrue = [](theVecType::iterator) -> bool { return true; };
const Expr *E = E_p->IgnoreParenImpCasts();
if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E))
- Erase<DeclRefExpr>(DR, PredTrue);
+ Erase<DeclRefExpr>(DR);
else if (const auto *ME = dyn_cast<MemberExpr>(E)) {
- Erase<MemberExpr>(ME, PredTrue);
+ Erase<MemberExpr>(ME);
}
}
@@ -210,9 +209,9 @@ private:
const Expr *E = lhs->IgnoreParenImpCasts();
auto pred = [assignKnown, numeratorKnown,
- denomExtVal](theVecType::iterator i) {
+ denomExtVal](const MallocOverflowCheck &Check) {
return assignKnown ||
- (numeratorKnown && (denomExtVal >= i->maxVal.getExtValue()));
+ (numeratorKnown && (denomExtVal >= Check.maxVal.getExtValue()));
};
if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E))
More information about the cfe-commits
mailing list