LLVM 19.0.0git
AlignOf.h
Go to the documentation of this file.
1//===--- AlignOf.h - Portable calculation of type alignment -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the AlignedCharArrayUnion class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_ALIGNOF_H
14#define LLVM_SUPPORT_ALIGNOF_H
15
16#include <type_traits>
17
18namespace llvm {
19
20/// A suitably aligned and sized character array member which can hold elements
21/// of any type.
22///
23/// This template is equivalent to std::aligned_union_t<1, ...>, but we cannot
24/// use it due to a bug in the MSVC x86 compiler:
25/// https://github.com/microsoft/STL/issues/1533
26/// Using `alignas` here works around the bug.
27template <typename T, typename... Ts> struct AlignedCharArrayUnion {
28 using AlignedUnion = std::aligned_union_t<1, T, Ts...>;
29 alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)];
30};
31
32} // end namespace llvm
33
34#endif // LLVM_SUPPORT_ALIGNOF_H
#define T
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A suitably aligned and sized character array member which can hold elements of any type.
Definition: AlignOf.h:27
char buffer[sizeof(AlignedUnion)]
Definition: AlignOf.h:29
std::aligned_union_t< 1, T, Ts... > AlignedUnion
Definition: AlignOf.h:28