From 3315bd0beb4cf23f838bd522a1f0e3fcc0a9fae2 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 17 Mar 2021 17:20:46 -0700 Subject: [PATCH] PR49619: Remove delayed call to noteFailed. This would assert if we hit the evaluation step limit between starting to delay the call and finishing. In any case, delaying the call was largely pointless as it doesn't really matter when we mark the evaluation as having had side effects. --- clang/lib/AST/ExprConstant.cpp | 31 +++++++------------------------ clang/test/Sema/integer-overflow.c | 9 +++++++++ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 4213beb..624b1bf 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -12472,25 +12472,6 @@ void DataRecursiveIntBinOpEvaluator::process(EvalResult &Result) { } namespace { -/// Used when we determine that we should fail, but can keep evaluating prior to -/// noting that we had a failure. -class DelayedNoteFailureRAII { - EvalInfo &Info; - bool NoteFailure; - -public: - DelayedNoteFailureRAII(EvalInfo &Info, bool NoteFailure = true) - : Info(Info), NoteFailure(NoteFailure) {} - ~DelayedNoteFailureRAII() { - if (NoteFailure) { - bool ContinueAfterFailure = Info.noteFailure(); - (void)ContinueAfterFailure; - assert(ContinueAfterFailure && - "Shouldn't have kept evaluating on failure."); - } - } -}; - enum class CmpResult { Unequal, Less, @@ -12858,12 +12839,14 @@ bool RecordExprEvaluator::VisitBinCmp(const BinaryOperator *E) { } bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { - // We don't call noteFailure immediately because the assignment happens after - // we evaluate LHS and RHS. - if (!Info.keepEvaluatingAfterFailure() && E->isAssignmentOp()) - return Error(E); + // We don't support assignment in C. C++ assignments don't get here because + // assignment is an lvalue in C++. + if (E->isAssignmentOp()) { + Error(E); + if (!Info.noteFailure()) + return false; + } - DelayedNoteFailureRAII MaybeNoteFailureLater(Info, E->isAssignmentOp()); if (DataRecursiveIntBinOpEvaluator::shouldEnqueue(E)) return DataRecursiveIntBinOpEvaluator(*this, Result).Traverse(E); diff --git a/clang/test/Sema/integer-overflow.c b/clang/test/Sema/integer-overflow.c index 39395d9..79e9294 100644 --- a/clang/test/Sema/integer-overflow.c +++ b/clang/test/Sema/integer-overflow.c @@ -203,3 +203,12 @@ struct s2 { } } }; + +void PR49619() { + int n; + n = ({ + while (1) + ; + 0; + }); +} -- 2.7.4