[PATCH] D139036: [Support][MathExtras] Add variadic SaturatingAdd
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 30 12:07:23 PST 2022
alexander-shaposhnikov added inline comments.
================
Comment at: llvm/include/llvm/Support/MathExtras.h:763-764
+ T XY = SaturatingAdd(X, Y, &Overflowed);
+ if (Overflowed)
+ return SaturatingAdd(std::numeric_limits<T>::max(), T(1), Args...);
+ return SaturatingAdd(XY, Z, Args...);
----------------
oontvoo wrote:
> P.S: perhaps just return max() here?
>
we need to set the overflow flag (this is what the recursive call does here),
since variadic templates are "greedy" i don't see an easy way (i'm aware of a few approaches but they'd require some extra code) to access the last argument (plus the last argument should have the default value).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139036/new/
https://reviews.llvm.org/D139036
More information about the llvm-commits
mailing list