r230292 - Restore the libc++ definition of max_align_t on Apple platforms

Dmitri Gribenko gribozavr at gmail.com
Mon Feb 23 17:06:22 PST 2015


Author: gribozavr
Date: Mon Feb 23 19:06:22 2015
New Revision: 230292

URL: http://llvm.org/viewvc/llvm-project?rev=230292&view=rev
Log:
Restore the libc++ definition of max_align_t on Apple platforms

Clang has introduced ::max_align_t in stddef.h in r201729, but libc++ was
already defining std::max_align_t on Darwin because there was none in the
global namespace.  After that Clang commit though, libc++ started defining
std::max_align_t to be a typedef for ::max_align_t, which has a different
definition.  This changed the ABI.  This commit restores the previous
definition.

rdar://19919394 rdar://18557982


Added:
    cfe/trunk/test/Headers/arm64-apple-ios-types.cpp
    cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp
    cfe/trunk/test/Headers/x86_64-apple-macosx-types.cpp
Modified:
    cfe/trunk/lib/Headers/__stddef_max_align_t.h

Modified: cfe/trunk/lib/Headers/__stddef_max_align_t.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__stddef_max_align_t.h?rev=230292&r1=230291&r2=230292&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/__stddef_max_align_t.h (original)
+++ cfe/trunk/lib/Headers/__stddef_max_align_t.h Mon Feb 23 19:06:22 2015
@@ -26,15 +26,18 @@
 #ifndef __CLANG_MAX_ALIGN_T_DEFINED
 #define __CLANG_MAX_ALIGN_T_DEFINED
 
-#ifndef _MSC_VER
+#if defined(_MSC_VER)
+typedef double max_align_t;
+#elif defined(__APPLE__)
+typedef long double max_align_t;
+#else
+// Define 'max_align_t' to match the GCC definition.
 typedef struct {
   long long __clang_max_align_nonce1
       __attribute__((__aligned__(__alignof__(long long))));
   long double __clang_max_align_nonce2
       __attribute__((__aligned__(__alignof__(long double))));
 } max_align_t;
-#else
-typedef double max_align_t;
 #endif
 
 #endif

Added: cfe/trunk/test/Headers/arm64-apple-ios-types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/arm64-apple-ios-types.cpp?rev=230292&view=auto
==============================================================================
--- cfe/trunk/test/Headers/arm64-apple-ios-types.cpp (added)
+++ cfe/trunk/test/Headers/arm64-apple-ios-types.cpp Mon Feb 23 19:06:22 2015
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios7.0 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+struct true_type {
+  static constexpr const bool value = true;
+};
+
+struct false_type {
+  static constexpr const bool value = false;
+};
+
+template <class _Tp, class _Up> struct is_same           : public false_type {};
+template <class _Tp>            struct is_same<_Tp, _Tp> : public true_type {};
+
+// Check that our 'is_same' works.
+static_assert(is_same<char, char>::value, "is_same is broken");
+static_assert(!is_same<char, char *>::value, "is_same is broken");
+
+template <class _Tp, unsigned _AlignOf, unsigned _SizeOf>
+struct check_type {
+  static constexpr const bool value =
+    (alignof(_Tp) == _AlignOf) && (sizeof(_Tp) == _SizeOf);
+};
+
+//===----------------------------------------------------------------------===//
+// Fundamental types
+//===----------------------------------------------------------------------===//
+
+static_assert(check_type<bool, 1, 1>::value, "bool is wrong");
+
+static_assert(check_type<char, 1, 1>::value, "char is wrong");
+static_assert(check_type<signed char, 1, 1>::value, "signed char is wrong");
+static_assert(check_type<unsigned char, 1, 1>::value, "unsigned char is wrong");
+
+static_assert(check_type<char16_t, 2, 2>::value, "char16_t is wrong");
+static_assert(check_type<char32_t, 4, 4>::value, "char32_t is wrong");
+static_assert(check_type<wchar_t, 4, 4>::value, "wchar_t is wrong");
+
+static_assert(check_type<short, 2, 2>::value, "short is wrong");
+static_assert(check_type<unsigned short, 2, 2>::value, "unsigned short is wrong");
+
+static_assert(check_type<int, 4, 4>::value, "int is wrong");
+static_assert(check_type<unsigned int, 4, 4>::value, "unsigned int is wrong");
+
+static_assert(check_type<long, 8, 8>::value, "long is wrong");
+static_assert(check_type<unsigned long, 8, 8>::value, "unsigned long is wrong");
+
+static_assert(check_type<long long, 8, 8>::value, "long long is wrong");
+static_assert(check_type<unsigned long long, 8, 8>::value, "unsigned long long is wrong");
+
+static_assert(check_type<float, 4, 4>::value, "float is wrong");
+static_assert(check_type<double, 8, 8>::value, "double is wrong");
+static_assert(check_type<long double, 8, 8>::value, "long double is wrong");
+
+static_assert(check_type<void *, 8, 8>::value, "'void *' is wrong");
+static_assert(check_type<int (*)(int), 8, 8>::value, "function pointer is wrong");
+
+//===----------------------------------------------------------------------===//
+// stdarg.h
+//===----------------------------------------------------------------------===//
+
+#include <stdarg.h>
+
+static_assert(check_type<va_list, 8, 8>::value, "va_list is wrong");
+
+//===----------------------------------------------------------------------===//
+// stddef.h
+//===----------------------------------------------------------------------===//
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <stddef.h>
+
+static_assert(is_same<long int, ::ptrdiff_t>::value, "::ptrdiff_t is wrong");
+static_assert(is_same<decltype(sizeof(char)), ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::rsize_t>::value, "::rsize_t is wrong");
+static_assert(is_same<long double, ::max_align_t>::value, "::max_align_t is wrong");
+
+#define __need_wint_t
+#include <stddef.h>
+
+static_assert(is_same<int, ::wint_t>::value, "::wint_t is wrong");
+

Added: cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp?rev=230292&view=auto
==============================================================================
--- cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp (added)
+++ cfe/trunk/test/Headers/thumbv7-apple-ios-types.cpp Mon Feb 23 19:06:22 2015
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -triple thumbv7-apple-ios7.0 -target-abi apcs-gnu -std=c++11 -verify %s
+// expected-no-diagnostics
+
+struct true_type {
+  static constexpr const bool value = true;
+};
+
+struct false_type {
+  static constexpr const bool value = false;
+};
+
+template <class _Tp, class _Up> struct is_same           : public false_type {};
+template <class _Tp>            struct is_same<_Tp, _Tp> : public true_type {};
+
+// Check that our 'is_same' works.
+static_assert(is_same<char, char>::value, "is_same is broken");
+static_assert(!is_same<char, char *>::value, "is_same is broken");
+
+template <class _Tp, unsigned _AlignOf, unsigned _SizeOf>
+struct check_type {
+  static constexpr const bool value =
+    (alignof(_Tp) == _AlignOf) && (sizeof(_Tp) == _SizeOf);
+};
+
+//===----------------------------------------------------------------------===//
+// Fundamental types
+//===----------------------------------------------------------------------===//
+
+static_assert(check_type<bool, 1, 1>::value, "bool is wrong");
+
+static_assert(check_type<char, 1, 1>::value, "char is wrong");
+static_assert(check_type<signed char, 1, 1>::value, "signed char is wrong");
+static_assert(check_type<unsigned char, 1, 1>::value, "unsigned char is wrong");
+
+static_assert(check_type<char16_t, 2, 2>::value, "char16_t is wrong");
+static_assert(check_type<char32_t, 4, 4>::value, "char32_t is wrong");
+static_assert(check_type<wchar_t, 4, 4>::value, "wchar_t is wrong");
+
+static_assert(check_type<short, 2, 2>::value, "short is wrong");
+static_assert(check_type<unsigned short, 2, 2>::value, "unsigned short is wrong");
+
+static_assert(check_type<int, 4, 4>::value, "int is wrong");
+static_assert(check_type<unsigned int, 4, 4>::value, "unsigned int is wrong");
+
+static_assert(check_type<long, 4, 4>::value, "long is wrong");
+static_assert(check_type<unsigned long, 4, 4>::value, "unsigned long is wrong");
+
+static_assert(check_type<long long, 8, 8>::value, "long long is wrong");
+static_assert(check_type<unsigned long long, 8, 8>::value, "unsigned long long is wrong");
+
+static_assert(check_type<float, 4, 4>::value, "float is wrong");
+static_assert(check_type<double, 8, 8>::value, "double is wrong");
+static_assert(check_type<long double, 4, 8>::value, "long double is wrong");
+
+static_assert(check_type<void *, 4, 4>::value, "'void *' is wrong");
+static_assert(check_type<int (*)(int), 4, 4>::value, "function pointer is wrong");
+
+//===----------------------------------------------------------------------===//
+// stdarg.h
+//===----------------------------------------------------------------------===//
+
+#include <stdarg.h>
+
+static_assert(check_type<va_list, 4, 4>::value, "va_list is wrong");
+
+//===----------------------------------------------------------------------===//
+// stddef.h
+//===----------------------------------------------------------------------===//
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <stddef.h>
+
+static_assert(is_same<int, ::ptrdiff_t>::value, "::ptrdiff_t is wrong");
+static_assert(is_same<decltype(sizeof(char)), ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::rsize_t>::value, "::rsize_t is wrong");
+static_assert(is_same<long double, ::max_align_t>::value, "::max_align_t is wrong");
+
+#define __need_wint_t
+#include <stddef.h>
+
+static_assert(is_same<int, ::wint_t>::value, "::wint_t is wrong");
+

Added: cfe/trunk/test/Headers/x86_64-apple-macosx-types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/x86_64-apple-macosx-types.cpp?rev=230292&view=auto
==============================================================================
--- cfe/trunk/test/Headers/x86_64-apple-macosx-types.cpp (added)
+++ cfe/trunk/test/Headers/x86_64-apple-macosx-types.cpp Mon Feb 23 19:06:22 2015
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+struct true_type {
+  static constexpr const bool value = true;
+};
+
+struct false_type {
+  static constexpr const bool value = false;
+};
+
+template <class _Tp, class _Up> struct is_same           : public false_type {};
+template <class _Tp>            struct is_same<_Tp, _Tp> : public true_type {};
+
+// Check that our 'is_same' works.
+static_assert(is_same<char, char>::value, "is_same is broken");
+static_assert(!is_same<char, char *>::value, "is_same is broken");
+
+template <class _Tp, unsigned _AlignOf, unsigned _SizeOf>
+struct check_type {
+  static constexpr const bool value =
+    (alignof(_Tp) == _AlignOf) && (sizeof(_Tp) == _SizeOf);
+};
+
+//===----------------------------------------------------------------------===//
+// Fundamental types
+//===----------------------------------------------------------------------===//
+
+static_assert(check_type<bool, 1, 1>::value, "bool is wrong");
+
+static_assert(check_type<char, 1, 1>::value, "char is wrong");
+static_assert(check_type<signed char, 1, 1>::value, "signed char is wrong");
+static_assert(check_type<unsigned char, 1, 1>::value, "unsigned char is wrong");
+
+static_assert(check_type<char16_t, 2, 2>::value, "char16_t is wrong");
+static_assert(check_type<char32_t, 4, 4>::value, "char32_t is wrong");
+static_assert(check_type<wchar_t, 4, 4>::value, "wchar_t is wrong");
+
+static_assert(check_type<short, 2, 2>::value, "short is wrong");
+static_assert(check_type<unsigned short, 2, 2>::value, "unsigned short is wrong");
+
+static_assert(check_type<int, 4, 4>::value, "int is wrong");
+static_assert(check_type<unsigned int, 4, 4>::value, "unsigned int is wrong");
+
+static_assert(check_type<long, 8, 8>::value, "long is wrong");
+static_assert(check_type<unsigned long, 8, 8>::value, "unsigned long is wrong");
+
+static_assert(check_type<long long, 8, 8>::value, "long long is wrong");
+static_assert(check_type<unsigned long long, 8, 8>::value, "unsigned long long is wrong");
+
+static_assert(check_type<float, 4, 4>::value, "float is wrong");
+static_assert(check_type<double, 8, 8>::value, "double is wrong");
+static_assert(check_type<long double, 16, 16>::value, "long double is wrong");
+
+static_assert(check_type<void *, 8, 8>::value, "'void *' is wrong");
+static_assert(check_type<int (*)(int), 8, 8>::value, "function pointer is wrong");
+
+//===----------------------------------------------------------------------===//
+// stdarg.h
+//===----------------------------------------------------------------------===//
+
+#include <stdarg.h>
+
+static_assert(check_type<va_list, 8, 24>::value, "va_list is wrong");
+
+//===----------------------------------------------------------------------===//
+// stddef.h
+//===----------------------------------------------------------------------===//
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <stddef.h>
+
+static_assert(is_same<long int, ::ptrdiff_t>::value, "::ptrdiff_t is wrong");
+static_assert(is_same<decltype(sizeof(char)), ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::size_t>::value, "::size_t is wrong");
+static_assert(is_same<long unsigned int, ::rsize_t>::value, "::rsize_t is wrong");
+static_assert(is_same<long double, ::max_align_t>::value, "::max_align_t is wrong");
+
+#define __need_wint_t
+#include <stddef.h>
+
+static_assert(is_same<int, ::wint_t>::value, "::wint_t is wrong");
+





More information about the cfe-commits mailing list