[llvm] 3654b93 - Fixed Windows build warnings (#68978)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 10:12:44 PDT 2023


Author: Nikita Kudriavtsev
Date: 2023-10-23T10:12:39-07:00
New Revision: 3654b93d57db060377b4858ff0bac6a5836d097c

URL: https://github.com/llvm/llvm-project/commit/3654b93d57db060377b4858ff0bac6a5836d097c
DIFF: https://github.com/llvm/llvm-project/commit/3654b93d57db060377b4858ff0bac6a5836d097c.diff

LOG: 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

Added: 
    

Modified: 
    llvm/include/llvm/Support/MathExtras.h

Removed: 
    


################################################################################
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