[Mlir-commits] [llvm] [mlir] Disable clang-tidy misc-include-cleaner (PR #83945)

Mehdi Amini llvmlistbot at llvm.org
Mon Mar 4 18:12:31 PST 2024


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/83945

This does not apply well to LLVM which intentionally rely on forward declarations. Also depending on the config flags passed to CMake the result can be different.

>From 9059be8b7367a0b7440b3fc744aa9c1a7277e556 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Mon, 4 Mar 2024 18:11:02 -0800
Subject: [PATCH] Disable clang-tidy misc-include-cleaner

This does not apply well to LLVM which intentionally rely on forward declarations.
Also depending on the config flags passed to CMake the result can be different.
---
 .clang-tidy                                           |  2 +-
 mlir/include/mlir/IR/Matchers.h                       | 11 +++++++++++
 .../Transforms/Utils/GreedyPatternRewriteDriver.cpp   |  3 +--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index 4e1cb114f43b2c..9cece0de812b8e 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,4 +1,4 @@
-Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-const-correctness,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-use-anonymous-namespace,readability-identifier-naming'
+Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-const-correctness,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-use-anonymous-namespace,readability-identifier-naming,-misc-include-cleaner'
 CheckOptions:
   - key:             readability-identifier-naming.ClassCase
     value:           CamelCase
diff --git a/mlir/include/mlir/IR/Matchers.h b/mlir/include/mlir/IR/Matchers.h
index f6417f62d09e8c..31a687dd422f60 100644
--- a/mlir/include/mlir/IR/Matchers.h
+++ b/mlir/include/mlir/IR/Matchers.h
@@ -15,9 +15,11 @@
 #ifndef MLIR_IR_MATCHERS_H
 #define MLIR_IR_MATCHERS_H
 
+#include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/OpDefinition.h"
+#include "llvm/Support/Casting.h"
 
 namespace mlir {
 
@@ -92,6 +94,15 @@ struct constant_op_binder {
     assert(succeeded(result) && "expected ConstantLike op to be foldable");
 
     if (auto attr = llvm::dyn_cast<AttrT>(foldedOp.front().get<Attribute>())) {
+      // Check that the attribute type matches the result type, folder shouldn't do
+      // this and maybe we should assert here, unfortunately llvm.constant accepts
+      // at the moment index attributes when the SSA type is integer.
+      if (auto typedAttr = dyn_cast<TypedAttr>(attr)) {
+        if (typedAttr.getType() != op->getResult(0).getType()) {
+          llvm::errs() << "Type mismatch: " << attr << "  " << *op << "\n";
+          return false;
+        }
+      }
       if (bind_value)
         *bind_value = attr;
       return true;
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index 51d2f5e01b7235..665536fb0c85ee 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -809,8 +809,7 @@ LogicalResult RegionPatternRewriteDriver::simplify(bool *changed) && {
       // accidentally reversing the constant order during processing.
       Attribute constValue;
       if (matchPattern(op, m_Constant(&constValue)))
-        if (!folder.insertKnownConstant(op, constValue))
-          return true;
+        return !folder.insertKnownConstant(op, constValue);
       return false;
     };
 



More information about the Mlir-commits mailing list