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

Henrich Lauko llvmlistbot at llvm.org
Tue Oct 20 23:11:29 PDT 2026


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

>From 56f4969818053ca5e51059d65b01c14a337e74c3 Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Tue, 20 Oct 2026 19:04:07 +0000
Subject: [PATCH] [mlir][LLVM] Verify LLVMStructType element types in get()

`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)
---
 mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td  |  9 ++++++++-
 mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp | 10 ++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

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



More information about the Mlir-commits mailing list