diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2017-06-12 21:59:18 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2017-06-12 21:59:18 +0000 |
commit | 54992386f37462c5393db45183c8cb8cc636be08 (patch) | |
tree | 844b599b8fb26c99edf8bc7ca996ed89142afb78 /clang/lib/Sema/SemaChecking.cpp | |
parent | 11d566acee0f58480dff03fdb6229e464cea5864 (diff) | |
download | bcm5719-llvm-54992386f37462c5393db45183c8cb8cc636be08.tar.gz bcm5719-llvm-54992386f37462c5393db45183c8cb8cc636be08.zip |
Revert r301742 which made ExprConstant checking apply to all full-exprs.
This patch also exposed pre-existing bugs in clang, see PR32864 and PR33140#c3 .
llvm-svn: 305239
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b794628db73..44184c73664 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9935,6 +9935,28 @@ void Sema::CheckBoolLikeConversion(Expr *E, SourceLocation CC) { ::CheckBoolLikeConversion(*this, E, CC); } +/// Diagnose when expression is an integer constant expression and its evaluation +/// results in integer overflow +void Sema::CheckForIntOverflow (Expr *E) { + // Use a work list to deal with nested struct initializers. + SmallVector<Expr *, 2> Exprs(1, E); + + do { + Expr *E = Exprs.pop_back_val(); + + if (isa<BinaryOperator>(E->IgnoreParenCasts())) { + E->IgnoreParenCasts()->EvaluateForOverflow(Context); + continue; + } + + if (auto InitList = dyn_cast<InitListExpr>(E)) + Exprs.append(InitList->inits().begin(), InitList->inits().end()); + + if (isa<ObjCBoxedExpr>(E)) + E->IgnoreParenCasts()->EvaluateForOverflow(Context); + } while (!Exprs.empty()); +} + namespace { /// \brief Visitor for expressions which looks for unsequenced operations on the /// same object. @@ -10436,7 +10458,7 @@ void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc, if (!E->isInstantiationDependent()) CheckUnsequencedOperations(E); if (!IsConstexpr && !E->isValueDependent()) - E->EvaluateForOverflow(Context); + CheckForIntOverflow(E); DiagnoseMisalignedMembers(); } |