James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Benjamin Hall <bhallctre@gmail.com> |
| 3 | Date: Mon, 23 Oct 2023 21:36:40 -0400 |
| 4 | Subject: [PATCH 32/32] Fix compilation of MathExtras.h on Windows with /sdl |
| 5 | |
| 6 | See https://github.com/llvm/llvm-project/pull/68978 |
| 7 | --- |
| 8 | llvm/include/llvm/Support/MathExtras.h | 5 ++++- |
| 9 | 1 file changed, 4 insertions(+), 1 deletion(-) |
| 10 | |
| 11 | diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h |
| 12 | index 5f034b694989d8ef24e0b249abd12a5c20146b97..03db6e4d92cb3b62ac3d8b3cbd97783817c6326b 100644 |
| 13 | --- a/llvm/include/llvm/Support/MathExtras.h |
| 14 | +++ b/llvm/include/llvm/Support/MathExtras.h |
| 15 | @@ -356,7 +356,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) { |
| 16 | inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { |
| 17 | assert(Align != 0 && (Align & (Align - 1)) == 0 && |
| 18 | "Align must be a power of 2"); |
| 19 | - return (Value + Align - 1) & -Align; |
| 20 | + // Replace unary minus to avoid compilation error on Windows: |
| 21 | + // "unary minus operator applied to unsigned type, result still unsigned" |
| 22 | + uint64_t negAlign = (~Align) + 1; |
| 23 | + return (Value + Align - 1) & negAlign; |
| 24 | } |
| 25 | |
| 26 | /// If non-zero \p Skew is specified, the return value will be a minimal integer |