AlignOf.h 1.3 KB

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