[Mlir-commits] [mlir] [mlir][ByteCodeReader] Fix bugs in EncodingReader::alignTo (PR #140660)
Peiming Liu
llvmlistbot at llvm.org
Mon May 19 19:36:49 PDT 2025
https://github.com/PeimingLiu created https://github.com/llvm/llvm-project/pull/140660
It seems that the number of padding value should be computed based on the relative distance between `ptr` and `buffer.begin()` (instead of the absolute address of `ptr`). Otherwise, the skipped padding value will be indeterministic and depends on the alignment of `buffer.begin()`?
Or is there any implicit assumption on the alignment of buffer that holds the bytecode?
>From 81c2cb1cdfe811279e28ae6e333d645d4c39d681 Mon Sep 17 00:00:00 2001
From: Peiming Liu <peiming at modular.com>
Date: Mon, 19 May 2025 19:27:42 -0700
Subject: [PATCH] [mlir][ByteCodeReader] Fix bugs in EncodingReader::alignTo
It seems that the number of padding value should be computed based on
the offset of the current pointer to the bytecode buffer
begin (instead of the absolute address of `ptr`). Otherwise, the
skipped padding value will be dependent on the alignment of
`buffer.begin()`?
---
mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index 1052946d4550b..793170dcc594c 100644
--- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -107,7 +107,8 @@ class EncodingReader {
return emitError("expected alignment to be a power-of-two");
auto isUnaligned = [&](const uint8_t *ptr) {
- return ((uintptr_t)ptr & (alignment - 1)) != 0;
+ unsigned offset = ptr - buffer.begin();
+ return (offset & (alignment - 1)) != 0;
};
// Shift the reader position to the next alignment boundary.
@@ -1506,7 +1507,7 @@ class mlir::BytecodeReader::Impl {
UseListOrderStorage(bool isIndexPairEncoding,
SmallVector<unsigned, 4> &&indices)
: indices(std::move(indices)),
- isIndexPairEncoding(isIndexPairEncoding){};
+ isIndexPairEncoding(isIndexPairEncoding) {};
/// The vector containing the information required to reorder the
/// use-list of a value.
SmallVector<unsigned, 4> indices;
More information about the Mlir-commits
mailing list