PR/56746
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 210 | nit: I'd probably report a separate message for the overflow case (cause it'd make debugging a tiny bit easier) | |
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 210 | nit: could you instead use an integer with a defined bit width: uint64_t? | |
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 210 |
How about uintptr_t ? | |
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 260 | I am known to be stupid. You do saturating add with uintptr_t and claim errors on uint32_t? Would it help to make the asserts into real errors? I like to be informed about malformed files in release builds. | |
addressed review comment:
- refactor code so that the overflow checks can be done in place
- remove redundant check
- fix off-by-one
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 260 | oops, sorry - forgot to update the error messages when I updated the types. | |
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 137 | 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) | |
| llvm/lib/Object/MachOObjectFile.cpp | ||
|---|---|---|
| 137 | sure! Thanks! | |
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)