summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-10-10 18:28:20 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-10-10 18:28:20 +0000
commitcaf3390d449ccc4a2eb97958dd3d456d1ea4bf90 (patch)
treeff8b87a69b97998ade8e050f2b93d9b31b1a6c6c /clang/lib/StaticAnalyzer
parent47aac5104302121ba64975cd4b51e27ef621131e (diff)
downloadbcm5719-llvm-caf3390d449ccc4a2eb97958dd3d456d1ea4bf90.tar.gz
bcm5719-llvm-caf3390d449ccc4a2eb97958dd3d456d1ea4bf90.zip
Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions, and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert behaviour. - Factor out evaluation of bitfield bit widths. - Fix a few places which would evaluate an expression twice: once to determine whether it is a constant expression, then again to get the value. llvm-svn: 141561
Diffstat (limited to 'clang/lib/StaticAnalyzer')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp10
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporter.cpp2
2 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
index 0f6b621bf7c..cf5501a4ac1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
@@ -118,9 +118,12 @@ private:
ASTContext &Context;
bool isIntZeroExpr(const Expr *E) const {
- return (E->getType()->isIntegralOrEnumerationType()
- && E->isEvaluatable(Context)
- && E->EvaluateAsInt(Context) == 0);
+ if (!E->getType()->isIntegralOrEnumerationType())
+ return false;
+ llvm::APSInt Result;
+ if (E->EvaluateAsInt(Result, Context))
+ return Result == 0;
+ return false;
}
void CheckExpr(const Expr *E_p) {
@@ -263,4 +266,3 @@ void MallocOverflowSecurityChecker::checkASTCodeBody(const Decl *D,
void ento::registerMallocOverflowSecurityChecker(CheckerManager &mgr) {
mgr.registerChecker<MallocOverflowSecurityChecker>();
}
-
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 9e1c12ce1f7..cdc9dcf7528 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -599,7 +599,7 @@ static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD,
}
if (GetRawInt)
- os << LHS->EvaluateAsInt(PDB.getASTContext());
+ os << LHS->EvaluateKnownConstInt(PDB.getASTContext());
os << ":' at line "
<< End.asLocation().getExpansionLineNumber();
OpenPOWER on IntegriCloud