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 "llvm/Support/Compiler.h"
17#include <cstddef>
18
19namespace llvm {
20
21namespace detail {
22
23template <typename T, typename... Ts> class AlignerImpl {
24 T t;
25 AlignerImpl<Ts...> rest;
26 AlignerImpl() = delete;
27};
28
29template <typename T> class AlignerImpl<T> {
30 T t;
31 AlignerImpl() = delete;
32};
33
34template <typename T, typename... Ts> union SizerImpl {
35 char arr[sizeof(T)];
36 SizerImpl<Ts...> rest;
37};
38
39template <typename T> union SizerImpl<T> { char arr[sizeof(T)]; };
40} // end namespace detail
41
42/// A suitably aligned and sized character array member which can hold elements
43/// of any type.
44///
45/// These types may be arrays, structs, or any other types. This exposes a
46/// `buffer` member which can be used as suitable storage for a placement new of
47/// any of these types.
48template <typename T, typename... Ts> struct AlignedCharArrayUnion {
49 alignas(::llvm::detail::AlignerImpl<T, Ts...>) char buffer[sizeof(
50 llvm::detail::SizerImpl<T, Ts...>)];
51};
52
53} // end namespace llvm
54
55#endif // LLVM_SUPPORT_ALIGNOF_H
56