Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <3EBS8QD55K8YJ.3M8DNLQQKVDYL@mforney.org>
Date: Sun, 21 Apr 2024 12:04:30 -0700
From: Michael Forney <mforney@...rney.org>
To: musl@...ts.openwall.com
Subject: Re: Alignment attribute in headers

Markus Wichmann <nullplan@....net> wrote:
> Am Sun, Apr 21, 2024 at 03:50:31PM +0000 schrieb Thorsten Glaser:
> > I haven’t looked at the C11 one.
> 
> C11's _Alignas can only raise alignment, not lower it. Alignment
> specifications with a lower number than the field already has are
> ignored. I can't believe the C++ guys screwed up so hard as to make
> lower alignment UB.

It's true that _Alignas can't lower alignment, but it's not ignored
if you specify a weaker alignment, it's a constraint violation:

C17 6.7.5p5:
> The combined effect of all alignment specifiers in a declaration
> shall not specify an alignment that is less strict than the
> alignment that would otherwise be required for the type of the
> object or member being declared.

This doesn't matter for the proposed alignment specifiers since
they are in architecture-specific headers where we know that the
specified alignment is not less than is required for the type.

However, in general, I think Thorsten's concern is valid. If you
specify some alignment that your application needs, but the
implementation already requires a stricter alignment, your program
has an error.

You could work around it by specifying two alignment specifiers:

	_Alignas(N) _Alignas(T) T x;

But anyway, this has veered a bit off-topic.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.