[PATCH] D138830: [llvm] Check for overflows when computing load-command's addresses.
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 30 05:51:53 PST 2022
oontvoo added inline comments.
================
Comment at: llvm/lib/Object/MachOObjectFile.cpp:137
+static uintptr_t SaturatingAddHelper(uintptr_t Arg1, uintptr_t Arg2,
+ uintptr_t Arg3, bool *Overflowed) {
----------------
alexander-shaposhnikov wrote:
> A slightly more general version:
> ```
> template <class T, class... Ts>
> std::enable_if_t<std::is_unsigned<T>::value, T>
> SaturatingAdd(T X, T Y, T Z, Ts... args) {
> bool Overflowed = false;
> T XY = SaturatingAdd(X, Y, &Overflowed);
> if (Overflowed)
> return SaturatingAdd(std::numeric_limits<T>::max(), 1, args...);
> return SaturatingAdd(XY, Z, args...);
> }
> ```
> (p.s. if you like - i can send a small patch with this addition to MathExtras)
sure! Thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138830/new/
https://reviews.llvm.org/D138830
More information about the llvm-commits
mailing list