Skip to content

Commit 81c2cb1

Browse files
committed
[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()`?
1 parent 6274cdb commit 81c2cb1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class EncodingReader {
107107
return emitError("expected alignment to be a power-of-two");
108108

109109
auto isUnaligned = [&](const uint8_t *ptr) {
110-
return ((uintptr_t)ptr & (alignment - 1)) != 0;
110+
unsigned offset = ptr - buffer.begin();
111+
return (offset & (alignment - 1)) != 0;
111112
};
112113

113114
// Shift the reader position to the next alignment boundary.
@@ -1506,7 +1507,7 @@ class mlir::BytecodeReader::Impl {
15061507
UseListOrderStorage(bool isIndexPairEncoding,
15071508
SmallVector<unsigned, 4> &&indices)
15081509
: indices(std::move(indices)),
1509-
isIndexPairEncoding(isIndexPairEncoding){};
1510+
isIndexPairEncoding(isIndexPairEncoding) {};
15101511
/// The vector containing the information required to reorder the
15111512
/// use-list of a value.
15121513
SmallVector<unsigned, 4> indices;

0 commit comments

Comments
 (0)