This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] 69759 - document __builtin_alloca and __builtin_alloca_with_align


On 02/16/2016 06:44 AM, Joseph Myers wrote:
On Tue, 16 Feb 2016, Martin Sebor wrote:

That said, I think it's worth pointing out that max_align_t has
nothing to do with standard C types.  The intent of the type is
to expose a type with the strictest alignment supported by
an implementation for an object of any type and with any storage
duration, not the alignment of the most strictly aligned basic
(or fundamental) type.

The minimum alignment for max_align_t (given the proposed fix for DR#445)
is defined in terms of standard types (where if various extensions in TRs
and TSes are implemented, the types in those are standard types for this
purpose).  While an implementation may choose to use a larger alignment
than the minimum, it's inefficient to do so, considering that malloc must
return suitably aligned memory even when the size allocated is smaller
than the alignment (and GCC chooses to use the minimum, modulo taking the
alignments that long long and long double have outside structures rather
than their possibly smaller alignments inside structures).

Max_align_t need not impact efficiency.  In C, the malloc alignment
also need not have an impact on the type since aligned_alloc returns
storage that is (or can be) more strictly aligned.

The original intent of max_align_t was to make it possible to query
the strictest alignment that an object can be defined with, regardless
of where it was defined (with what storage duration).  In C++, this
alignment is constrained by dynamic allocation because there's no way
(yet) to request overaligned heap memory (C++ doesn't specify
aligned_alloc()).  Since C does provide aligned_alloc() to allocate
overaligned memory, max_align_t is more likely to be constrained by
the other storage durations.  So for example on a C implementation
like Linux with GLIBC, while conforming, to define max_align_t to
_Alignof(long double) is redunant and less than useful.  Programs
can trivially query the alignment of basic types.  What they cannot
do (but may need to do) is query the greatest supported alignment in
all contexts/storage durations.

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]