[Mlir-commits] [mlir] acb162d - [mlir][LLVM] Verify LLVMStructType element types in get() (#234091)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 21 02:06:04 PDT 2026
Author: Henrich Lauko
Date: 2026-10-21T11:05:59+02:00
New Revision: acb162d974706998af2e3045f618a8d66abfdf09
URL: https://github.com/llvm/llvm-project/commit/acb162d974706998af2e3045f618a8d66abfdf09
DIFF: https://github.com/llvm/llvm-project/commit/acb162d974706998af2e3045f618a8d66abfdf09.diff
LOG: [mlir][LLVM] Verify LLVMStructType element types in get() (#234091)
`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)
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td
mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
Removed:
################################################################################
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