[PATCH] D55057: [Headers] Make max_align_t match GCC's implementation.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 29 08:40:51 PST 2018


EricWF created this revision.
EricWF added reviewers: rsmith, jyknight.

GCC also considers the `__float128` type when constructing `max_align_t`. Clang's definition is intended to exactly match GCC's, so this patch make Clang do the same.

NOTE: This breaks the ABI of `max_align_t` by changing its size and alignment on 32 bit linux platforms.


Repository:
  rC Clang

https://reviews.llvm.org/D55057

Files:
  lib/Headers/__stddef_max_align_t.h
  test/Headers/c11.c


Index: test/Headers/c11.c
===================================================================
--- test/Headers/c11.c
+++ test/Headers/c11.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -fmodules -fmodules-cache-path=%t %s -D__STDC_WANT_LIB_EXT1__=1
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i686-pc-win32 -fms-compatibility-version=17.00 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -triple i386-unknown-linux-gnu %s
 
 noreturn int f(); // expected-error 1+{{}}
 
@@ -29,8 +30,17 @@
 _Static_assert(sizeof(max_align_t) >= sizeof(long double), "");
 _Static_assert(alignof(max_align_t) >= alignof(long double), "");
 
+
 #ifdef _MSC_VER
 _Static_assert(sizeof(max_align_t) == sizeof(double), "");
+_Static_assert(alignof(max_align_t) == alignof(double), "");
+#elif defined(__APPLE__)
+_Static_assert(sizeof(max_align_t) == sizeof(long double), "");
+_Static_assert(alignof(max_align_t) == alignof(long double), "");
+#else
+// Test compatibility with GCC's version
+_Static_assert(sizeof(max_align_t) >= sizeof(__float128), "");
+_Static_assert(alignof(max_align_t) >= alignof(__float128), "");
 #endif
 
 // If we are freestanding, then also check RSIZE_MAX (in a hosted implementation
Index: lib/Headers/__stddef_max_align_t.h
===================================================================
--- lib/Headers/__stddef_max_align_t.h
+++ lib/Headers/__stddef_max_align_t.h
@@ -37,6 +37,10 @@
       __attribute__((__aligned__(__alignof__(long long))));
   long double __clang_max_align_nonce2
       __attribute__((__aligned__(__alignof__(long double))));
+#ifdef __i386__
+  __float128 __clang_max_align_nonce3
+    __attribute__((__aligned__(__alignof__(__float128))));
+#endif
 } max_align_t;
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55057.175877.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181129/2ca8c30d/attachment.bin>


More information about the cfe-commits mailing list