aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-24 22:11:45 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-24 22:11:45 +0000
commitad48a500596d7d678b99c7f94326cfa856c3b49f (patch)
tree0c85477f72f28170b11277f9bce540baa6719270 /lib/Sema/SemaChecking.cpp
parent6c23bd2890acdc87b9d52ac65108d36ecb703c0b (diff)
Patch to check for integer overflow. It has been
commented on and approved by Richard Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173377 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 0d8f764df5..9af16f3201 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -5183,6 +5183,18 @@ void Sema::CheckImplicitConversions(Expr *E, SourceLocation CC) {
AnalyzeImplicitConversions(*this, E, CC);
}
+/// Diagnose when expression is an integer constant expression and its evaluation
+/// results in integer overflow
+void Sema::CheckForIntOverflow (Expr *E) {
+ if (const BinaryOperator *BExpr = dyn_cast<BinaryOperator>(E->IgnoreParens())) {
+ unsigned Opc = BExpr->getOpcode();
+ if (Opc != BO_Add && Opc != BO_Sub && Opc != BO_Mul)
+ return;
+ llvm::SmallVector<PartialDiagnosticAt, 4> Diags;
+ E->EvaluateForOverflow(Context, &Diags);
+ }
+}
+
namespace {
/// \brief Visitor for expressions which looks for unsequenced operations on the
/// same object.
@@ -5622,9 +5634,12 @@ void Sema::CheckUnsequencedOperations(Expr *E) {
}
}
-void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc) {
+void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc,
+ bool IsConstexpr) {
CheckImplicitConversions(E, CheckLoc);
CheckUnsequencedOperations(E);
+ if (!IsConstexpr && !E->isValueDependent())
+ CheckForIntOverflow(E);
}
void Sema::CheckBitFieldInitialization(SourceLocation InitLoc,