[Mlir-commits] [mlir] [mlir][LLVM] Verify LLVMStructType element types in get() (PR #234091)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 20 23:13:46 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-llvm

Author: Henrich Lauko (xlauko)

<details>
<summary>Changes</summary>

`using Base::verifyInvariants` pulled in StorageUserBase's variadic no-op
verifier. `StorageUserBase::get` passes a `unique_function` emitter, which
binds to that template exactly, so `getLiteral` skipped the element type
check even in assertions builds.

Drop the `using` and add a storage-key overload. Sub-element replacement
needs it because it rebuilds literal structs with `Base::get(ctx, key)`.

Assisted-by: Claude Code (Claude Opus 5.5)

---
Full diff: https://github.com/llvm/llvm-project/pull/234091.diff


2 Files Affected:

- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td (+8-1) 
- (modified) mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp (+10) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
index 910256aa4617b7..080f78e080d63a 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
@@ -274,7 +274,14 @@ def LLVMStructType : LLVMType<"LLVMStruct", "struct", [
     static LogicalResult
     verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
                      ArrayRef<Type> types, bool);
-    using Base::verifyInvariants;
+    /// Verifies a literal struct's storage key, which sub-element replacement
+    /// passes to get().
+    template <typename StorageKey>
+    static LogicalResult
+    verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
+                     const StorageKey &key) {
+      return verifyInvariants(emitError, key.getTypeList(), key.isPacked());
+    }
   }];
 
   let hasCustomAssemblyFormat = 1;
diff --git a/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp b/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
index 083dec819a0e05..df19caec693976 100644
--- a/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
+++ b/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
@@ -17,3 +17,13 @@ TEST_F(LLVMIRTest, IsStructTypeMutable) {
   ASSERT_TRUE(bool(structTy));
   ASSERT_TRUE(structTy.hasTrait<TypeTrait::IsMutable>());
 }
+
+#if GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
+using LLVMIRDeathTest = LLVMIRTest;
+
+TEST_F(LLVMIRDeathTest, StructTypeGetVerifiesElementTypes) {
+  EXPECT_DEATH(
+      LLVMStructType::getLiteral(&context, {LLVMVoidType::get(&context)}),
+      "invalid LLVM structure element type");
+}
+#endif

``````````

</details>


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


More information about the Mlir-commits mailing list