[PATCH] D20755: [MC] Check the upper bound in truncate assertion

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 15:00:54 PDT 2016


LGTM

On 27 May 2016 at 17:57, Petr Hosek <phosek at chromium.org> wrote:
> phosek created this revision.
> phosek added a reviewer: rafael.
> phosek added subscribers: rafael, phosek, llvm-commits.
> phosek set the repository for this revision to rL LLVM.
>
> The truncateToSize function already has assertion to check the
> lower boundary for the number bytes, but it does not check the
> upper boundary which could still lead to usage errors.
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D20755
>
> Files:
>   lib/MC/MCAsmStreamer.cpp
>
> Index: lib/MC/MCAsmStreamer.cpp
> ===================================================================
> --- lib/MC/MCAsmStreamer.cpp
> +++ lib/MC/MCAsmStreamer.cpp
> @@ -303,7 +303,7 @@
>  }
>
>  static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
> -  assert(Bytes && "Invalid size!");
> +  assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
>    return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
>  }
>
>
>


More information about the llvm-commits mailing list