[Mlir-commits] [mlir] [mlir][LLVM] Verify LLVMStructType element types in get() (PR #234091)
Henrich Lauko
llvmlistbot at llvm.org
Tue Oct 20 22:59:52 PDT 2026
https://github.com/xlauko created https://github.com/llvm/llvm-project/pull/234091
`using Base::verifyInvariants` brought StorageUserBase's variadic no-op
verifier into scope. `StorageUserBase::get` passes a `unique_function`
emitter, which binds exactly to that template, so `getLiteral` never ran
the element type check, even with assertions enabled.
Replace the `using` with a storage-key overload, which sub-element
replacement needs when it rebuilds the type from its key.
Assisted-by: Claude Code (Claude Opus 5.5)
>From 2534e46ffb3b60c8b6aa27d3dee2e2c7329a87c4 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` brought StorageUserBase's variadic no-op
verifier into scope. `StorageUserBase::get` passes a `unique_function`
emitter, which binds exactly to that template, so `getLiteral` never ran
the element type check, even with assertions enabled.
Replace the `using` with a storage-key overload, which sub-element
replacement needs when it rebuilds the type from its key.
Assisted-by: Claude Code (Claude Opus 5.5)
---
mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td | 11 ++++++++++-
mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp | 8 ++++++++
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..29dcdeda113559 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
@@ -274,7 +274,16 @@ def LLVMStructType : LLVMType<"LLVMStruct", "struct", [
static LogicalResult
verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
ArrayRef<Type> types, bool);
- using Base::verifyInvariants;
+ /// Verifies a storage key, used when replacing sub-elements.
+ template <typename StorageKey>
+ static LogicalResult
+ verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
+ const StorageKey &key) {
+ if (key.isIdentified())
+ return verifyInvariants(emitError, key.getIdentifier(),
+ key.isOpaque());
+ 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..0e817c74534b2f 100644
--- a/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
+++ b/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
@@ -17,3 +17,11 @@ TEST_F(LLVMIRTest, IsStructTypeMutable) {
ASSERT_TRUE(bool(structTy));
ASSERT_TRUE(structTy.hasTrait<TypeTrait::IsMutable>());
}
+
+#if GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
+TEST_F(LLVMIRTest, StructTypeGetVerifiesElementTypes) {
+ EXPECT_DEATH(
+ LLVMStructType::getLiteral(&context, {LLVMVoidType::get(&context)}),
+ "invalid LLVM structure element type");
+}
+#endif
More information about the Mlir-commits
mailing list