1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This test confirms the actual data types of types defined by various
6 // C/C++ standards. We must ensure that the actual types match on all
12 #include <sys/types.h>
16 #include "native_client/tests/toolchain/utils.h"
18 // Checks size and alignment.
20 void CheckSizeAndAlignOf(const char* test_type, int size, unsigned int align) {
22 snprintf(error, sizeof(error), "sizeof(%s)=%d", test_type, sizeof(T));
23 ASSERT(sizeof(T) == size, error);
24 snprintf(error, sizeof(error), "alignof(%s)=%u", test_type, __alignof__(T));
25 ASSERT(__alignof__(T) == align, error);
28 // Checks type equivalency.
29 template<typename T, typename A>
30 void CheckType(const char* test_type) {
32 snprintf(error, sizeof(error), "typeid(%s)=%s", test_type, typeid(T).name());
33 ASSERT(typeid(T) == typeid(A), error);
36 // Checks type equivalency and size and alignment.
37 template<typename T, typename A>
38 void CheckTypeAndSizeAndAlignOf(const char* test_type,
41 CheckType<T, A>(test_type);
42 CheckSizeAndAlignOf<T>(test_type, size, align);
47 // TODO(eaeltsin): jmp_buf must be the same on all platforms.
48 // CheckSizeAndAlignOf<jmp_buf>("jmp_buf", 48, 8); // x86-64
49 // CheckSizeAndAlignOf<jmp_buf>("jmp_buf", 36, 4); // x86-32
52 CheckTypeAndSizeAndAlignOf<size_t, unsigned int>("size_t", 4, 4);
53 CheckTypeAndSizeAndAlignOf<ptrdiff_t, int>("ptrdiff_t", 4, 4);
54 CheckSizeAndAlignOf<wchar_t>("wchar_t", 4, 4);
57 CheckSizeAndAlignOf<va_list>("va_list", 16, 4);
60 CheckTypeAndSizeAndAlignOf<ssize_t, int>("ssize_t", 4, 4);
61 // TODO(eaeltsin): add more types