diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-26 23:19:32 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-26 23:19:32 +0000 |
commit | 9f7df0c068318db3d1d336290accaf25c37e0b05 (patch) | |
tree | 3d567df053f88eddf82451484835d17c6e98c2c3 /clang/lib/Sema/SemaChecking.cpp | |
parent | 9f658582350570ce458bd909d3022546227d48c4 (diff) | |
download | bcm5719-llvm-9f7df0c068318db3d1d336290accaf25c37e0b05.tar.gz bcm5719-llvm-9f7df0c068318db3d1d336290accaf25c37e0b05.zip |
Revert r301742, which caused us to try to evaluate all full-expressions.
Also add testcases for a bunch of expression forms that cause our evaluator to
crash. See PR33140 and PR32864 for crashes that this was causing.
This reverts r305287, which reverted r305239, which reverted r301742. The
previous revert claimed that buildbots were broken, but did not add any
testcases and the buildbots have lost all memory of what was wrong here.
Changes to test/OpenMP are not reverted; another change has triggered those
tests to change their output in the same way that r301742 did.
llvm-svn: 306346
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 5201796adbb..845c4bf61b7 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9936,6 +9936,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. @@ -10437,7 +10459,7 @@ void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc, if (!E->isInstantiationDependent()) CheckUnsequencedOperations(E); if (!IsConstexpr && !E->isValueDependent()) - E->EvaluateForOverflow(Context); + CheckForIntOverflow(E); DiagnoseMisalignedMembers(); } |