Skip to content

Commit 3654b93

Browse files
authored
Fixed Windows build warnings (#68978)
Fixed a warning encountered during Windows compilation: - narrowing conversion size_t -> int32_t - unary minus operator applied to unsigned type, result still unsigned
1 parent e01c7d5 commit 3654b93

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/include/llvm/Support/MathExtras.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) {
382382
inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) {
383383
assert(Align != 0 && (Align & (Align - 1)) == 0 &&
384384
"Align must be a power of 2");
385-
return (Value + Align - 1) & -Align;
385+
// Replace unary minus to avoid compilation error on Windows:
386+
// "unary minus operator applied to unsigned type, result still unsigned"
387+
uint64_t negAlign = (~Align) + 1;
388+
return (Value + Align - 1) & negAlign;
386389
}
387390

388391
/// If non-zero \p Skew is specified, the return value will be a minimal integer

0 commit comments

Comments
 (0)