[Mlir-commits] [mlir] [MLIR][TableGen] Warn on APInt parameter without custom comparator (PR #135970)

Tobias Gysi llvmlistbot at llvm.org
Wed Apr 16 10:25:18 PDT 2025


================
@@ -678,8 +678,18 @@ void DefGen::emitStorageClass() {
   emitConstruct();
   // Emit the storage class members as public, at the very end of the struct.
   storageCls->finalize();
-  for (auto &param : params)
+  for (auto &param : params) {
+    if (param.getCppType().contains("APInt") && !param.hasCustomComparator()) {
+      PrintWarning(
+          def.getLoc(),
+          "Using a raw APInt parameter without a custom comparator is "
+          "discouraged because an assert in the equality operator is "
+          "triggered when the two APInts have different bit widths. This can "
+          "lead to unexpected crashes. Consider using an `APIntParameter` or "
+          "providing a custom comparator.");
----------------
gysit wrote:

```suggestion
          "Using a raw APInt parameter without a custom comparator is "
          "not supported because an assert in the equality operator is "
          "triggered when the two APInts have different bit widths. This can "
          "lead to unexpected crashes. Use an `APIntParameter` or "
          "provide a custom comparator.");
```
nit: I would probably strengthen the warning a bit?

https://github.com/llvm/llvm-project/pull/135970


More information about the Mlir-commits mailing list