Files
allwpilib/upstream_utils/llvm_patches/0034-Fix-AlignedCharArrayUnion-for-C-23.patch
PJ Reiniger 32cd2ddf8e [upstream_utils] Remove patch that results in building with NDEBUG causing ODR issues (#8539)
Semiwrap / meson / robotpy define `NDEBUG` when building their software
in all modes, while `allwplib` only does it when building debug. This
causes the size of `DenseMap` to differ between the shared libraries
built here, and the extension modules built in `mostrobotpy`, causing
segfaults when you try to execute code that uses `DenseMap`. This is not
a problem with the robotpy code in `allwpilib`, because bazel uses the
exact same compiler flags when building the shared libraries and
pybind11 extensions.
2026-01-03 13:32:16 -08:00

40 lines
1.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Sat, 13 Jul 2024 15:24:30 -0700
Subject: [PATCH 34/35] Fix AlignedCharArrayUnion for C++23
---
llvm/include/llvm/Support/AlignOf.h | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/Support/AlignOf.h b/llvm/include/llvm/Support/AlignOf.h
index f586d7f182aab6e56b7fae6ae98a7cd89e63976c..ca98a564733a07a5e16122d31805e970bf76b673 100644
--- a/llvm/include/llvm/Support/AlignOf.h
+++ b/llvm/include/llvm/Support/AlignOf.h
@@ -13,20 +13,16 @@
#ifndef LLVM_SUPPORT_ALIGNOF_H
#define LLVM_SUPPORT_ALIGNOF_H
-#include <type_traits>
+#include <algorithm>
+#include <cstddef>
namespace llvm {
/// A suitably aligned and sized character array member which can hold elements
/// of any type.
-///
-/// This template is equivalent to std::aligned_union_t<1, ...>, but we cannot
-/// use it due to a bug in the MSVC x86 compiler:
-/// https://github.com/microsoft/STL/issues/1533
-/// Using `alignas` here works around the bug.
-template <typename T, typename... Ts> struct AlignedCharArrayUnion {
- using AlignedUnion = std::aligned_union_t<1, T, Ts...>;
- alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)];
+template <typename... Ts> struct AlignedCharArrayUnion {
+ alignas((std::max)({alignof(Ts)...}))
+ std::byte buffer[(std::max)({static_cast<size_t>(1), sizeof(Ts)...})];
};
} // end namespace llvm