[Mlir-commits] [mlir] [mlir][ByteCodeReader] Fix bugs in EncodingReader::alignTo (PR #140660)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon May 19 19:37:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-mlir
Author: Peiming Liu (PeimingLiu)
<details>
<summary>Changes</summary>
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?
---
Full diff: https://github.com/llvm/llvm-project/pull/140660.diff
1 Files Affected:
- (modified) mlir/lib/Bytecode/Reader/BytecodeReader.cpp (+3-2)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/140660
More information about the Mlir-commits
mailing list