Re: [PATCH] perf build: Restore {0} initializer since GCC-15

From: James Clark
Date: Wed Mar 19 2025 - 07:29:02 EST




On 19/03/2025 11:04 am, Leo Yan wrote:
GCC-15 release claims [1]:

{0} initializer in C or C++ for unions no longer guarantees clearing
of the whole union (except for static storage duration initialization),
it just initializes the first union member to zero. If initialization
of the whole union including padding bits is desirable, use {} (valid
in C23 or C++) or use -fzero-init-padding-bits=unions option to
restore old GCC behavior.

This new behaviour might cause stale and unexpected data we defined in
Perf. Add the -fzero-init-padding-bits=unions option for entirely
zeroing union structures.


Do we need this? I don't see any unions initialized in that way. In fact there is only one struct initialized with {0}, the other handful are char*s but I don't think either are affected.

Adding options that allow people to add more non standard code doesn't feel very portable or in the spirit of doing it the right way. Maybe there's an argument that it guards against future mistakes, but it's not mentioned in the commit message.