[PATCH] D138830: [llvm] Check for overflows when computing load-command's addresses.
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 29 15:00:09 PST 2022
alexander-shaposhnikov 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) {
----------------
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)
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