[Mlir-commits] [mlir] [MLIR][Bytecode] Enforce alignment requirements (PR #157004)
Mehdi Amini
llvmlistbot at llvm.org
Fri Sep 5 04:15:17 PDT 2025
================
@@ -117,6 +119,57 @@ TEST(Bytecode, MultiModuleWithResource) {
checkResourceAttribute(*roundTripModule);
}
+TEST(Bytecode, AlignmentFailure) {
+ MLIRContext context;
+ Builder builder(&context);
+ ParserConfig parseConfig(&context);
+ OwningOpRef<Operation *> module =
+ parseSourceString<Operation *>(irWithResources, parseConfig);
+ ASSERT_TRUE(module);
+
+ // Write the module to bytecode.
+ MockOstream ostream;
+ EXPECT_CALL(ostream, reserveExtraSpace).WillOnce([&](uint64_t space) {
+ ostream.buffer = std::make_unique<std::byte[]>(space);
+ ostream.size = space;
+ });
+ ASSERT_TRUE(succeeded(writeBytecodeToFile(module.get(), ostream)));
+
+ // Create copy of buffer which is not aligned to requested resource alignment.
+ std::string buffer((char *)ostream.buffer.get(),
+ (char *)ostream.buffer.get() + ostream.size);
+ size_t bufferSize = buffer.size();
+
+ // Increment into the buffer until we get to a power of 2 alignment that is
+ // not 32 bit aligned.
----------------
joker-eph wrote:
32 bits or bytes? I would think that 32 bits would be `Align(4)`.
Also the comment is a bit strange: a buffer is always aligned to a power of two since 1 is a power of two. That probably deserves some rephrasing (and maybe code adjustment).
https://github.com/llvm/llvm-project/pull/157004
More information about the Mlir-commits
mailing list