[llvm] Fixed Windows build warnings (PR #68978)

Nikita Kudriavtsev via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 13:51:46 PDT 2023


https://github.com/nikita-kud updated https://github.com/llvm/llvm-project/pull/68978

>From dbe31c884062e1f7193cc9165534156a114ab89e Mon Sep 17 00:00:00 2001
From: Nikita Kudriavtsev <nikita.kudriavtsev at intel.com>
Date: Tue, 4 Apr 2023 21:00:01 +0000
Subject: [PATCH] Fix compilation on Windows

---
 llvm/include/llvm/Support/MathExtras.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index dc095941fdc8a9f..7278c4eb7695887 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -382,7 +382,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



More information about the llvm-commits mailing list