[PATCH] D78964: [Support] Handle signed padding in decodeLEB128 + add multi-sized tests

Nicolas Guillemot via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 13:31:10 PDT 2020


nlguillemot created this revision.
nlguillemot added reviewers: bogner, qcolombet, fhahn, rtereshin.
Herald added a project: LLVM.

When decoding a LEB128 number, it might be followed by an arbitrary
amount of padding. The padding bits might require more bits than we can
actually store in the representation of the result, but this is not a problem
as long as the padding bits all correspond to a sext/zext. Previously,
the decoding was not handling this case, which caused decodeULEB128 to fail
with the error message "uleb128 too big for uint64". It didn't fail for
decodeSLEB128, but that's because decodeSLEB128 didn't check for
overflow at all, so it was probably doing something dubious in terms of
C++ language spec.

This commit fixes various issues with handling padding bits. This patch
allows numbers to have extra bits that would normally overflow the
representation, as long as those extra bits correspond to the sext/zext
of the representation. Once some bits appear that don't fit the
sext/zext, then it produes an error about the overflow.

Additionally, this patch masks the bits passed to insertLo7InPlace to try to
avoid signed overflow in its implementation.

Additionally, this patch adds tests for decoding and encoding with
8-bit, 16-bit, and 32-bit types as the representation. Implementing
these tests required the overflow issue to be solved, because otherwise
tests of decodeLEB128 into a uint8_t would fail due to an incorrectly
detected overflow.


https://reviews.llvm.org/D78964

Files:
  llvm/include/llvm/Support/LEB128.h
  llvm/include/llvm/Support/LEB128CodecInfo.h
  llvm/unittests/Support/LEB128Test.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78964.260444.patch
Type: text/x-patch
Size: 15346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/1df8652b/attachment.bin>


More information about the llvm-commits mailing list