Re: Subject: [ANN] Lua 5.5.1 (rc1) now available

Berwyn Hoyt <[email protected]> Fri, 17 Jul 2026 08:50:16 +1000
Newsgroups gmane.comp.lang.lua.general
Message-ID <CAKToXm8LpmQvvA5G2iR-jDpJ-nV1RS_k+Cn3+vy6Po8-TmCB7A@mail.gmail.com>
--000000000000ad2f490656c24548
Content-Type: text/plain; charset="UTF-8"

>
> > lua-5.5.1/src/lstate.c:352:14: runtime error: member access within
> > misaligned address 0x7d51507e0608 for type 'union GCUnion', which
> requires
> > 16 byte alignment
> > 0x7d51507e0608: note: pointer points here
> >  be be be be  be be be be be be be be  08 08 01 00 be be be be  be be be
> be
> > be be be be  80 00 7e 50
> >               ^
> > [...]
>
> I believe gcc is being overzealous here and possibly breaking the C
> standard.  The standard says this:
>
>    "A pointer to a union object, suitably converted, points to each of
>     its members [...], and vice versa."
>
> So, if a member is an int, it should be valid to convert a pointer to
> int (with its 4-byte alignment) to a pointer to the union, and then
> convert it back to a pointer to int.


I see a possible flaws with your reasoning:

   - Firstly in the abstract: regarding what the standard says, if a
   hypothetical union contains, for example, both a (4-byte) int and an
   (8-byte) pointer, then it must be 8-byte aligned to work with the
   pointer, even if it only needs 4-byte alignment to work with the int. Such
   a union would be 8-byte aligned and the statement you quote from the
   standard would be true. The reverse, however, does not follow from the
   standard: you cannot necessarily take an arbitrary int pointer (which may
   be 4-byte aligned) and convert it to the union (because that must be 8-byte
   aligned). So the standard is not infringed.
   - In this particular case, all of GCUnion's members begin with
   CommonHeader, whose first entry is a pointer (*next), and pointers must be
   8-byte aligned (on a 64-bit machine). So converting an arbitrary 4-byte
   aligned int to GCUnion, as was done here, is illegal in case you actually
   use the union as GCUnion. I guess the compiler isn't clever enough to work
   out that you're going to convert the GCUnion back to an int without using
   it as a GCUnion.

Cheers,
Berwyn

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAKToXm8LpmQvvA5G2iR-jDpJ-nV1RS_k%2BCn3%2Bvy6Po8-TmCB7A%40mail.gmail.com.

--000000000000ad2f490656c24548
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_quote"><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid=
 rgb(204,204,204);padding-left:1ex">&gt; lua-5.5.1/src/lstate.c:352:14: run=
time error: member access within<br>
&gt; misaligned address 0x7d51507e0608 for type &#39;union GCUnion&#39;, wh=
ich requires<br>
&gt; 16 byte alignment<br>
&gt; 0x7d51507e0608: note: pointer points here<br>
&gt; =C2=A0be be be be=C2=A0 be be be be be be be be=C2=A0 08 08 01 00 be b=
e be be=C2=A0 be be be be<br>
&gt; be be be be=C2=A0 80 00 7e 50<br>
&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br>
&gt; [...]<br>
<br>
I believe gcc is being overzealous here and possibly breaking the C<br>
standard.=C2=A0 The standard says this:<br>
<br>
=C2=A0 =C2=A0&quot;A pointer to a union object, suitably converted, points =
to each of<br>
=C2=A0 =C2=A0 its members [...], and vice versa.&quot;<br>
<br>
So, if a member is an int, it should be valid to convert a pointer to<br>
int (with its 4-byte alignment) to a pointer to the union, and then<br>
convert it back to a pointer to int.</blockquote><div><br></div><div class=
=3D"gmail_default" style=3D"font-family:tahoma,sans-serif">I see a possible=
 flaws with your reasoning:</div><div class=3D"gmail_default" style=3D"font=
-family:tahoma,sans-serif"><ul><li>Firstly in the abstract: regarding what =
the standard says, if a hypothetical union contains, for example, both a (4=
-byte) int and an (8-byte) pointer, then it must be 8-byte aligned to work =
with the pointer,=C2=A0even if it only needs 4-byte alignment to work with =
the int. Such a union would be 8-byte aligned and the statement you quote f=
rom the standard would be true. The reverse, however, does not follow from =
the standard: you cannot necessarily take an arbitrary int pointer (which m=
ay be 4-byte aligned) and convert it to the union (because that must be 8-b=
yte aligned). So the=C2=A0standard is not infringed.</li><li>In this partic=
ular case, all of GCUnion&#39;s members begin=C2=A0with CommonHeader, whose=
 first entry is a pointer (*next), and pointers must be 8-byte aligned (on =
a 64-bit machine). So converting an arbitrary 4-byte aligned int to GCUnion=
, as was done here, is illegal in case you actually use the union as GCUnio=
n. I guess the compiler isn&#39;t clever enough to work out that you&#39;re=
 going to convert the GCUnion back to an int without using it as a GCUnion.=
</li></ul><div>Cheers,</div><div>Berwyn</div></div></div></div>
</div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;lua-l&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">lua-l+unsubsc=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
lua-l/CAKToXm8LpmQvvA5G2iR-jDpJ-nV1RS_k%2BCn3%2Bvy6Po8-TmCB7A%40mail.gmail.=
com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msg=
id/lua-l/CAKToXm8LpmQvvA5G2iR-jDpJ-nV1RS_k%2BCn3%2Bvy6Po8-TmCB7A%40mail.gma=
il.com</a>.<br />

--000000000000ad2f490656c24548--