From 7f13b2a91a4888b191824e06652a02bf4d2b23be Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Mon, 23 Oct 2023 21:04:38 -0400 Subject: [PATCH 1/2] Fix compilation of MathExtras.h on Windows with /sdl Fix copied from the LLVM main branch --- .../src/main/native/thirdparty/llvm/include/wpi/MathExtras.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h index b77cce7bd9d..ed3b2b1efc3 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h @@ -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 From f8adb250aa2ddb0cf92a509f1bcd06c5341e3a09 Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Mon, 23 Oct 2023 21:47:22 -0400 Subject: [PATCH 2/2] Add a patch to upstream_utils I reverted the previous file changes locally and ran the python script with the latest patch and confirmed that there were no changes compared to the MathExtras.h header compared to the previous commit. --- ...-of-MathExtras.h-on-Windows-with-sdl.patch | 26 +++++++++++++++++++ upstream_utils/update_llvm.py | 1 + 2 files changed, 27 insertions(+) create mode 100644 upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch diff --git a/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch b/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch new file mode 100644 index 00000000000..52956f95baa --- /dev/null +++ b/upstream_utils/llvm_patches/0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Benjamin Hall +Date: Mon, 23 Oct 2023 21:36:40 -0400 +Subject: [PATCH 32/32] Fix compilation of MathExtras.h on Windows with /sdl + +See https://github.com/llvm/llvm-project/pull/68978 +--- + 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 5f034b694989d8ef24e0b249abd12a5c20146b97..03db6e4d92cb3b62ac3d8b3cbd97783817c6326b 100644 +--- a/llvm/include/llvm/Support/MathExtras.h ++++ b/llvm/include/llvm/Support/MathExtras.h +@@ -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 diff --git a/upstream_utils/update_llvm.py b/upstream_utils/update_llvm.py index 3414ec4deb6..edbd3df716f 100755 --- a/upstream_utils/update_llvm.py +++ b/upstream_utils/update_llvm.py @@ -209,6 +209,7 @@ def main(): "0029-Use-C-20-bit-header.patch", "0030-Remove-DenseMap-GTest-printer-test.patch", "0031-Replace-deprecated-std-aligned_storage_t.patch", + "0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch", ]: git_am( os.path.join(wpilib_root, "upstream_utils/llvm_patches", f),