[clang] 3315bd0 - PR49619: Remove delayed call to noteFailed.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 17 17:25:34 PDT 2021


Author: Richard Smith
Date: 2021-03-17T17:25:18-07:00
New Revision: 3315bd0beb4cf23f838bd522a1f0e3fcc0a9fae2

URL: https://github.com/llvm/llvm-project/commit/3315bd0beb4cf23f838bd522a1f0e3fcc0a9fae2
DIFF: https://github.com/llvm/llvm-project/commit/3315bd0beb4cf23f838bd522a1f0e3fcc0a9fae2.diff

LOG: 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.

Added: 
    

Modified: 
    clang/lib/AST/ExprConstant.cpp
    clang/test/Sema/integer-overflow.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4213beb915af..624b1bfde4e6 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 39395d9bc1fd..79e9294067de 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;
+  });
+}


        


More information about the cfe-commits mailing list