Diagnose if a SLEB128 is too large to fit in an int64_t.
authorRichard Smith <richard@metafoo.co.uk>
Wed, 27 Jan 2021 07:36:01 +0000 (23:36 -0800)
committerRichard Smith <richard@metafoo.co.uk>
Tue, 2 Feb 2021 22:33:34 +0000 (14:33 -0800)
commit32e98f05fe108e7b25dcf2031c499b96a1436e1d
treedab672a7f106290e1d7a62dd9303f7de471a8015
parente1a4322f8136788228d915a7384c5679b39dfeed
Diagnose if a SLEB128 is too large to fit in an int64_t.

Previously we'd hit UB due to an invalid left shift operand.

Also fix the WASM emitter to properly use SLEB128 encoding instead of
ULEB128 encoding for signed fields so that negative numbers don't
result in overly-large values that we can't read back any more.

In passing, don't diagnose a non-canonical ULEB128 that fits in a uint64_t but
has redundant trailing zero bytes.

Reviewed By: dblaikie, aardappel

Differential Revision: https://reviews.llvm.org/D95510
llvm/include/llvm/Support/LEB128.h
llvm/lib/ObjectYAML/WasmEmitter.cpp
llvm/unittests/Support/LEB128Test.cpp