[Mlir-commits] [mlir] [mlir][bytecode] Use getChecked<T>() in bytecode reading to avoid crashes (PR #186145)

Mehdi Amini llvmlistbot at llvm.org
Fri Mar 13 06:28:25 PDT 2026


================
@@ -527,6 +527,36 @@ auto get(MLIRContext *context, Ts &&...params) {
   }
 }
 
+namespace detail {
+template <typename T, typename... Ts>
+using has_get_checked_method = decltype(T::getChecked(std::declval<Ts>()...));
+} // namespace detail
+
+/// Helper method analogous to `get`, but uses `getChecked` when available to
+/// allow graceful failure on invalid parameters instead of asserting.
+///
+/// Only the no-context form of `getChecked` is tried here. Types that expose
+/// `getChecked(emitError, params...)` without a leading `MLIRContext*` (e.g.
+/// MemRefType, VectorType, RankedTensorType) will use it for graceful failure.
+/// Everything else falls back to `get<T>()`.  We intentionally do NOT try
+/// `T::getChecked(emitError, context, params...)`: for types that only inherit
+/// the base `StorageUserBase::getChecked` template (e.g. ArrayAttr), that
+/// template instantiation requires a complete storage type which may not be
----------------
joker-eph wrote:

StorageUserBase is only emitted in the .cpp.inc , the .h.inc has a forward declaration. So it is opaque to us...

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


More information about the Mlir-commits mailing list