diff options
author | Peiming Liu <peiming@modular.com> | 2025-05-19 19:27:42 -0700 |
---|---|---|
committer | Peiming Liu <peiming@modular.com> | 2025-05-19 19:33:58 -0700 |
commit | 81c2cb1cdfe811279e28ae6e333d645d4c39d681 (patch) | |
tree | 7341d033545822f89d91510d9e787033d6baab8d | |
parent | 6274cdb9a6714908c8a4e30d2ef0bf22a6949065 (diff) | |
download | llvm-users/peimingliu/fix-align-to.zip llvm-users/peimingliu/fix-align-to.tar.gz llvm-users/peimingliu/fix-align-to.tar.bz2 |
[mlir][ByteCodeReader] Fix bugs in EncodingReader::alignTousers/peimingliu/fix-align-to
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()`?
-rw-r--r-- | mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 1052946..793170d 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -107,7 +107,8 @@ public: 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 @@ private: 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; |