================
@@ -0,0 +1,476 @@
+// RUN: %check_clang_tidy %s llvm-mlir-use-after-erase %t
+
+namespace mlir {
+
+class BitVector {};
+class ValueRange {};
+class Location {};
+
+class Operation {
+public:
+ void destroy();
+ void erase();
+
+ void dump();
+ Location getLoc() {
+ return Location{};
+ }
+};
+
+class OpState {
+public:
+ Operation *operator->() const { return state; }
+ Operation *getOperation() { return state; }
+
+private:
+ Operation *state;
+};
+class Op : public OpState {};
+
+class Builder {};
+class OpBuilder : public Builder {};
+class RewriterBase : public OpBuilder {
+public:
+ virtual ~RewriterBase() = default;
+
+ virtual void eraseOp(Operation *op);
+ Operation *eraseOpResults(Operation *op, const BitVector &eraseIndices);
+
+ virtual void replaceOp(Operation *op, ValueRange newValues);
+ virtual void replaceOp(Operation *op, Operation *newOp);
+ template <typename OpTy, typename... Args>
+ OpTy replaceOpWithNewOp(Operation *op, Args &&...args);
+};
+class PatternRewriter : public RewriterBase {};
+
+} // namespace mlir
+
+namespace test {
+class MyOp : public mlir::Op {
+};
+
+
+} // namespace test
+
+namespace {
+
+void consume([[maybe_unused]] mlir::Operation *op) {
+}
+
+struct NoReturnDestructor {
+ [[noreturn]] ~NoReturnDestructor();
+};
+#define FATAL() NoReturnDestructor()
+
+// A type that happens to have erase() / destroy() methods but is unrelated to
mlir::Operation
+class NotAnOperation {
+public:
+ void erase() {}
+ void destroy() {}
+ void dump() {}
+};
+
+// A type that exposes operator-> / getOperation() returning mlir::Operation*
+// but is not derived from mlir::OpState
+class NotAnOp {
+public:
+ mlir::Operation* operator->() const { return op; }
+ mlir::Operation* getOperation() const { return op; }
+private:
+ mlir::Operation* op;
+};
+
+// A type that has RewriterBase-like method names but is not derived from
mlir::RewriterBase
+class NotARewriter {
+public:
+ void eraseOp(mlir::Operation *op) {}
+ void replaceOp(mlir::Operation *op, mlir::Operation *newOp) {}
+};
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// General tests
+
+void useAfterDestroy() {
+ mlir::Operation* op{};
+ op->destroy();
+ op->dump();
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operation 'op' is used after
it was erased [llvm-mlir-use-after-erase]
----------------
zeyi2 wrote:
```suggestion
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operation 'op' is used after it
was erased
```
Same as below
https://github.com/llvm/llvm-project/pull/210727
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits