From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Coly Li <colyli@fnnas.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] bcache: Avoid -Wflex-array-member-not-at-end warning
Date: Tue, 11 Nov 2025 22:28:57 +0900 [thread overview]
Message-ID: <a956504a-55af-4c2c-95a0-15663435624a@embeddedor.com> (raw)
In-Reply-To: <7g2dkwi2nzxe2luykodsknobzr5bkl23d5mbahkyo7adhg55oy@6uisoc7jzgy6>
On 11/11/25 22:17, Coly Li wrote:
> On Mon, Nov 10, 2025 at 07:58:58PM +0800, Gustavo A. R. Silva wrote:
>> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
>> getting ready to enable it, globally.
>>
>> Use the new TRAILING_OVERLAP() helper to fix the following warning:
>>
>> drivers/md/bcache/bset.h:330:27: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>>
>> This helper creates a union between a flexible-array member (FAM) and a
>> set of MEMBERS that would otherwise follow it.
>>
>> This overlays the trailing MEMBER struct btree_iter_set stack_data[MAX_BSETS];
>> onto the FAM struct btree_iter::data[], while keeping the FAM and the start
>> of MEMBER aligned.
>>
>> The static_assert() ensures this alignment remains, and it's
>> intentionally placed inmediately after the corresponding structures --no
>> blank line in between.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>> ---
>> drivers/md/bcache/bset.h | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
>> index 011f6062c4c0..6ee2c6a506a2 100644
>> --- a/drivers/md/bcache/bset.h
>> +++ b/drivers/md/bcache/bset.h
>> @@ -327,9 +327,13 @@ struct btree_iter {
>> /* Fixed-size btree_iter that can be allocated on the stack */
>>
>> struct btree_iter_stack {
>> - struct btree_iter iter;
>> - struct btree_iter_set stack_data[MAX_BSETS];
>> + /* Must be last as it ends in a flexible-array member. */
>> + TRAILING_OVERLAP(struct btree_iter, iter, data,
>> + struct btree_iter_set stack_data[MAX_BSETS];
>> + );
>> };
>> +static_assert(offsetof(struct btree_iter_stack, iter.data) ==
>> + offsetof(struct btree_iter_stack, stack_data));
>>
>
> I have to say this is ugly. Not the patch, but the gcc 14 warning option
> of such coding style. Look at TRAILING_OVERLAP() usage here, this is not
> C, this is something to fix a gcc bug which cannot handle FAM properly.
This is not a GCC bug.
>
> Gustavo, this complain is not to you, just I feel a bit sad how GCC makes
> the code comes to such an ugly way, and it makes things much complicated.
> For anyone doesn't have deep understanding of TRAILING_OVERLAP(), I
> highly suspect whether he or she can understand what happens here.
>
> Andrew and Gustavo, is this a mandatary to fix FAM in such way? If yes
> I take the patch and keep my own opinion. If not, I'd like to see gcc
> fixes its bug, for the this code I don't see the author does things
> wrong.
This is a false positive that needs to be addressed in some way in order to
enable -Wflex-array-member-not-at-end in mainline.
Here you can take a look at the patches I (and others) have submitted to
modify similar code over the last year:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?qt=grep&q=-Wflex-array-member-not-at-end
Thanks
-Gustavo
next prev parent reply other threads:[~2025-11-11 13:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 10:58 Gustavo A. R. Silva
2025-11-11 13:17 ` Coly Li
2025-11-11 13:28 ` Gustavo A. R. Silva [this message]
2025-11-11 13:43 ` Coly Li
2025-11-13 4:24 ` Gustavo A. R. Silva
2025-11-24 8:34 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a956504a-55af-4c2c-95a0-15663435624a@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=akpm@linux-foundation.org \
--cc=colyli@fnnas.com \
--cc=gustavoars@kernel.org \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®