[PATCH] Define max_align_t in C++11 and C11 mode

David Majnemer david.majnemer at gmail.com
Fri Oct 18 16:17:50 PDT 2013


On Fri, Oct 18, 2013 at 3:58 PM, Joerg Sonnenberger <joerg at britannica.bec.de
> wrote:

> On Fri, Oct 18, 2013 at 03:22:23PM -0700, Arthur O'Dwyer wrote:
> > On Fri, Oct 18, 2013 at 3:01 PM, Joerg Sonnenberger
> > <joerg at britannica.bec.de> wrote:
> > > On Fri, Oct 18, 2013 at 10:22:41AM -0700, David Majnemer wrote:
> > >>
> > >> This implementation of max_align_t disagrees with gcc
> > [...]
> > >> gcc's alignof(max_align_t): 8
> > >> clang's alignof(max_align_t): 4
> > >
> > > Well, what is it supposed to do in the face of SSE2 registers? For all
> > > basic types, the IA32 ABI mandates at most 32bit alignment. With the
> > > compiler extensions it can certainly be at least 128bit.
> >
> > The Standard seems pretty clear on the subject:
> > alignof(std::max_align_t) should be the largest "fundamental
> > alignment" supported by the implementation. It's
> > implementation-defined whether "overaligned types" (such as Altivec
> > 'vector' types, perhaps) exist, but certainly the invariant must be
> > maintained that alignof(std::max_align_t) >= alignof(long long).
> >
> > It's also implied (7.6.2) that alignof(std::max_align_t) is the
> > largest value that can be reliably passed to alignas() in absolutely
> > any context. If Clang can't reliably align things to 8-byte
> > boundaries, then choosing alignof(max_align_t)==4 might actually be
> > defensible.
> >
> > On a modern x86 compiler, I would expect alignof(max_align_t) to be at
> > least 16, since users will reasonably assume that if an address is
> > aligned to a max_align_t boundary, then it's safe to store any object
> > type there.
>
> The danger of that assumption is that it can trigger stack-realignment
> on systems that still use the SYSV ABI. Those will by default only align
> to 32bit. I don't know whether any system still in use gives less than
> 128bit alignment for malloc() return values.


32-bit Windows CRT malloc() is specified to return 64-bit alignment.


> Frankly, this seems to be
> ill-defined...
>

The C1X standard says:
"The pointer returned if the allocation succeeds is suitably aligned so
that it may be assigned to a pointer to any type of object with a
fundamental alignment requirement and then used to access such an object or
an array of such objects in the space allocated (until the space is
explicitly deallocated)."


>
> Joerg
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131018/81881f1b/attachment.html>


More information about the cfe-commits mailing list