Issue 0445: Issues with alignment in C11, part 2

This issue has been automatically converted from the original issue lists and some formatting may not have been preserved.

Authors: WG 14, Joseph Myers
Date: 2013-07-23
Reference document: N1731
Submitted against: C11 / C17
Status: Fixed
Fixed in: C17
Converted from: n2396.htm

Summary

There are various deficiencies in the C11 text about alignment requirements.

Issue 2: Contexts in which alignments are supported

6.2.8#2 defines "fundamental alignment": "A fundamental alignment is represented by an alignment less than or equal to the greatest alignment supported by the implementation in all contexts, which is equal to _Alignof (max_align_t)."

6.2.8#3 defines "extended alignment": "An extended alignment is represented by an alignment greater than _Alignof (max_align_t). It is implementation-defined whether any extended alignments are supported and the contexts in which they are supported. A type having an extended alignment requirement is an over-aligned type."

6.2.8#4 defines "valid alignment", saying "Alignments are represented as values of the type size_t. Valid alignments include only those values returned by an _Alignof expression for fundamental types, plus an additional implementation-defined set of values, which may be empty. Every valid alignment value shall be a nonnegative integral power of two.".

max_align_t is specified in 7.19#2 as "an object type whose alignment is as great as is supported by the implementation in all contexts".

The memory management functions in 7.22.3 are defined to return a pointer "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". In the case of aligned_alloc, there may be a stricter requirement given by the alignment passed to the function, but the alignment passed to the function can't result in memory any less-aligned than a fundamental alignment requirement. The alignment requirement still applies even if the size is too small for any object requiring the given alignment (see the response to C90 DR#075).

There are various problems with the above:

The following principles seem natural for any fix for this issue:


Comment from WG14 on 2017-11-03:

Oct 2013 meeting

Committee Discussion

Apr 2014 meeting

Committee Discussion

Oct 2014 meeting

Committee Discussion

The proposed changes have raised no concerns and so the committee has agreed to use them as the following Proposed Technical Corrigendum.

Proposed Technical Corrigendum

Change 6.2.8#2 to:

A fundamental alignment is a valid alignment less than or equal to _Alignof (max_align_t). Fundamental alignments shall be supported by the implementation for objects of all storage durations. The alignment requirements of the following types shall be fundamental alignments:

In 6.2.8#3, change

"the contexts in"

to

"the storage durations of objects for which".

In 6.2.8#4, change

"those values returned by an _Alignof expression for fundamental types"

to

"fundamental alignments".

In 6.7.5#3, change

"in the context in which it appears"

to

"for an object of the storage duration, if any, being declared".

Add a new constraint at the end of 6.7.5#3:

"An object shall not be declared with an over-aligned type with an extended alignment requirement not supported by the implementation for an object of that storage duration.".

In 7.19#2, change

"whose alignment is as great as is supported by the implementation in all contexts"

to

"whose alignment is the greatest fundamental alignment".