================
@@ -0,0 +1,365 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MlirUseAfterEraseCheck.h"
+#include "../utils/ExprSequence.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
+#include "clang/Analysis/CFG.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include <optional>
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::utils;
+
+namespace clang::tidy::llvm_check {
+
+namespace {
+
+/// Contains information about a use-after-erase.
+struct UseAfterErase {
+  // The DeclRefExpr that constituted the use of the operation.
+  const DeclRefExpr *DeclRef;
+
+  // Is the order in which the erase and the use are evaluated undefined?
+  bool EvaluationOrderUndefined = false;
+
+  // Does the use happen in a later loop iteration than the erase?
+  //
+  // We default to false and change it to true if required in find().
+  bool UseHappensInLaterLoopIteration = false;
+};
+
+/// Finds uses of an `mlir::Operation` variable that are reachable after the
+/// operation was erased (and maintains state required by the various internal
+/// helper functions).
+class UseAfterEraseFinder {
----------------
Harald-R wrote:

There is some room for reducing duplication with the `bugprone-use-after-move` 
check. I can move the base implementation of the finder in a common util and 
make some of its methods virtual, if that is desired.

https://github.com/llvm/llvm-project/pull/210727
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to