On Wed, Oct 22, 2025 at 1:31 PM Peter0x44 <[email protected]> wrote:
>
> Oct 22, 2025 9:28:07 AM Richard Biener <[email protected]>:
>
> > On Wed, Oct 22, 2025 at 2:22 AM Peter Damianov <[email protected]>
> > wrote:
> >>
> >> C23 adds a memalignment function to determine the alignment of a pointer.
> >> Given how simple it is (convert pointer to an integer then return (p &
> >> -p)),
> >> GCC should support expanding it inline.
> >>
> >> This patch implements __builtin_memalignment which expands to p & -p
> >
> > Does C23 add '__builtin_memalignment' literally? If not, why do we need
> > an indirection through a builtin and not implement that in terms of p & -p
> > directly?
>
> I don't understand this question. I did check the following:
>
> size_t memalignment(void*);
>
> And the call to it was inline.
>
> Could you please elaborate?
Ah, so C23 documents a new function in the standard library called memalignment?
And not a new keyword like _Alignof, etc.?
For that it looks reasonable. Please be defensive as to expected arguments.
Consider
struct X { int bla; } memalignment ();
void foo()
{
struct X x = memalignment ();
}
or similar. GCC is happily considering mis-matching declarations as builtins.
Richard.
>