Bug 193594 - stddef.h should define max_align_t
Summary: stddef.h should define max_align_t
Status: Closed DUPLICATE of bug 210890
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-standards (Nobody)
URL:
Keywords: needs-qa
Depends on: 210890
Blocks:
  Show dependency treegraph
 
Reported: 2014-09-13 03:11 UTC by lichray
Modified: 2018-06-25 04:19 UTC (History)
4 users (show)

See Also:
koobs: mfc-stable10?
koobs: mfc-stable9?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lichray 2014-09-13 03:11:32 UTC
C11 max_align_t does not work with both base system clang and ports clang (clang has those defined under lib/Headers but we don't install them, while we do install GCC's fixed headers for GCC in ports, e.g. /usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd8.4/4.9.2/include/stddef.h).

FreeBSD already defines C11 additions in /usr/include/stdlib.h, and we should do the same for max_align_t.

I copy-pasted clang's implementation to /usr/include/stddef.h and everything works fine:

#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
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;
#endif

GCC's implementation queries for defined(__STDC_VERSION__) and defined(__cplusplus); the struct is the same.
Comment 1 lichray 2014-09-13 03:28:12 UTC
One more issue needs to be fixed for libc++ in base if we make the change:

In cstddef, the latest version contains

#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T)
// Re-use the compiler's <stddef.h> max_align_t where possible.
using ::max_align_t;
#else
typedef long double max_align_t;
#endif

which is hacky, but the version we use is even worse

typedef long double max_align_t;

, which is bad.

After we updated /usr/include/stddef.h, we should patch our libc++ to say just

using ::max_align_t;

in C++11 mode (exactly what libstdc++ does).
Comment 2 Ed Schouten freebsd_committer freebsd_triage 2016-07-09 13:12:46 UTC
(In reply to lichray from comment #1)

I think the more reliable solution would be to let our <stddef.h>:

#define __CLANG_MAX_ALIGN_T_DEFINED

That way it's impossible for the logic on our side and libc++ to conflict.
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2018-06-24 21:17:13 UTC
Dup of PR210890, already closed.
Comment 4 Kubilay Kocak freebsd_committer freebsd_triage 2018-06-25 04:19:49 UTC
Correctly mark as duplicate

*** This bug has been marked as a duplicate of bug 210890 ***