[llvm-commits] [llvm] r151883 - in /llvm/trunk: include/llvm/ADT/Hashing.h include/llvm/Support/type_traits.h unittests/ADT/HashingTest.cpp
Duncan Sands
baldrick at free.fr
Fri Mar 2 01:39:29 PST 2012
Hi Chandler,
> --- llvm/trunk/include/llvm/Support/type_traits.h (original)
> +++ llvm/trunk/include/llvm/Support/type_traits.h Fri Mar 2 03:26:36 2012
> @@ -125,6 +125,24 @@
> template<typename T> struct is_pointer : false_type {};
> template<typename T> struct is_pointer<T*> : true_type {};
>
> +/// \brief Metafunction to compute whether a type requires alignment padding.
> +/// When true, an object of this type will have padding bytes inside its
> +/// 'sizeof' bytes.
> +template<typename T> class is_alignment_padded {
> + struct pod_size_tester { T t; char c; };
> +public:
> + enum { value = offsetof(pod_size_tester, c) != sizeof(T) };
I don't think this can ever fail. It could only fail if char had an alignment
> 1. The "natural offset" for a field of type S following t is sizeof(T). It
may then be pushed further away if this position is not compatible with the
alignment of S. In this case the alignment of char is compatible with every
position.
> +};
> +
> +/// \brief Metafunction to determine whether an adjacent pair of two types will
> +/// require padding between them due to alignment.
> +template<typename T, typename U> class is_pod_pair_padded {
> + struct pod_pair { T t; U u; };
> + struct pod_char_pair { T t; char c; };
> +public:
> + enum { value = offsetof(pod_pair, u) != offsetof(pod_char_pair, c) };
> +};
This one seems OK.
Ciao, Duncan.
More information about the llvm-commits
mailing list