Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Matt Coster <Matt.Coster@imgtec.com>
To: "linux-sparse@vger.kernel.org" <linux-sparse@vger.kernel.org>
Subject: [BUG] Alignment of structure members does not always propagate
Date: Thu, 3 Jul 2025 11:19:28 +0000	[thread overview]
Message-ID: <ea14a74d-2da3-480e-bb84-33904aaeb10b@imgtec.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1293 bytes --]

Hi,

I started investigating this in response to [1], where it appears an
aligned attribute on a structure member is not being propagated out to
the containing structure by Sparse.

Removing the explicit alignment on the containing structure appears to
resolve this issue, suggesting to me that Sparse *can* correctly
evaluate the overall structure alignment, but that this value is
overridden by the explicit alignment attribute rather than (correctly)
being coerced upwards.

Here's a minimal reproduction, which compiles just fine with gcc/clang
but fails both assertions with Sparse (which considers the "correct"
size and alignment to be 8).

   struct outer_struct {
   	int member __attribute__((__aligned__(64)));
   } __attribute__((__aligned__(8)));

   _Static_assert(sizeof(struct outer_struct) == 64, "bad size");
   _Static_assert(_Alignof(struct outer_struct) == 64, "bad align");

I don't really have time myself to dig into this any further, but I
wanted to share what I'd discovered so far in case somebody far more
knowledgeable than myself can easily identify the issue within Sparse.

Cheers,
Matt

[1]: https://lore.kernel.org/r/20250606-sprase-reasoning-comments-v1-1-433c0ff11a09@imgtec.com

-- 
Matt Coster
E: matt.coster@imgtec.com

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

                 reply	other threads:[~2025-07-03 11:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ea14a74d-2da3-480e-bb84-33904aaeb10b@imgtec.com \
    --to=matt.coster@imgtec.com \
    --cc=linux-sparse@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).