[wpiutil] Fix compilation of MathExtras.h on Windows with /sdl (#5809)

Fix copied from the LLVM main branch.
This commit is contained in:
Benjamin Hall
2023-10-24 00:35:13 -04:00
committed by GitHub
parent b03a7668f9
commit 63ef585d4b
3 changed files with 31 additions and 1 deletions

View File

@@ -356,7 +356,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) {
inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) {
assert(Align != 0 && (Align & (Align - 1)) == 0 &&
"Align must be a power of 2");
return (Value + Align - 1) & -Align;
// Replace unary minus to avoid compilation error on Windows:
// "unary minus operator applied to unsigned type, result still unsigned"
uint64_t negAlign = (~Align) + 1;
return (Value + Align - 1) & negAlign;
}
/// If non-zero \p Skew is specified, the return value will be a minimal integer