Re: [PATCH] Fix strict aliasing violations in a few string functions

Bruno Haible via Gnulib discussion list <[email protected]> Sun, 26 Jul 2026 13:15:56 +0200
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <7853364.DvuYhMxLoT@cagnes>
Hi Lasse,

> It's undefined behavior.
> 
> * lib/memchr.c (__memchr): Add _GL_ATTRIBUTE_MAY_ALIAS to
> the longword typedef.
> * lib/memchr2.c (memchr2): Likewise.
> * lib/memrchr.c (__memrchr): Likewise.
> * lib/rawmemchr.c (rawmemchr): Likewise.
> * lib/strchrnul.c (strchrnul): Likewise.

I guess you are arguing with ISO C 23, § 6.5.1.(7),
where "effective type" is defined in § 6.5.1.(6)
and "character types" is defined in § 6.2.5.(20).

Looking at these functions only, one could view 'longword'
as the effective type of this memory, and 'unsigned char' as a valid
alternate way of accessing it.

Are you concerned about these functions being inlined?
They are in separate compilation units.

Are you concerned about LTO optimization (global inlining across
compilation units)?

Bruno