[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / include / llvm / Support / AlignOf.h
blobeb42542b777ff8fecde68708a1a938c4e6e98acc
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_SUPPORT_ALIGNOF_H
14 #define LLVM_SUPPORT_ALIGNOF_H
16 #include "llvm/Support/Compiler.h"
17 #include <cstddef>
19 namespace llvm {
21 namespace detail {
23 template <typename T, typename... Ts> class AlignerImpl {
24 T t;
25 AlignerImpl<Ts...> rest;
26 AlignerImpl() = delete;
29 template <typename T> class AlignerImpl<T> {
30 T t;
31 AlignerImpl() = delete;
34 template <typename T, typename... Ts> union SizerImpl {
35 char arr[sizeof(T)];
36 SizerImpl<Ts...> rest;
39 template <typename T> union SizerImpl<T> { char arr[sizeof(T)]; };
40 } // end namespace detail
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.
48 template <typename T, typename... Ts> struct AlignedCharArrayUnion {
49 alignas(::llvm::detail::AlignerImpl<T, Ts...>) char buffer[sizeof(
50 llvm::detail::SizerImpl<T, Ts...>)];
53 } // end namespace llvm
55 #endif // LLVM_SUPPORT_ALIGNOF_H