public inbox for linux-sparse@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben.dooks@codethink.co.uk>
To: Jeff Johnson <jeff.johnson@oss.qualcomm.com>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-sparse@vger.kernel.org
Subject: Re: issue with _Static_assert and __builtin()s
Date: Tue, 10 Feb 2026 14:25:14 +0000	[thread overview]
Message-ID: <1b4aab7e-28ad-4b8f-a2f4-fac639e923bb@codethink.co.uk> (raw)
In-Reply-To: <c57d33cc-dab1-4846-9c51-c358710a01c9@oss.qualcomm.com>

On 09/02/2026 16:25, Jeff Johnson wrote:
> On 1/7/26 21:41, Dan Carpenter wrote:
>> On Wed, Jan 07, 2026 at 07:41:45PM +0000, Ben Dooks wrote:
>>> So I am looking at why the Linux kernel's check for nul characters
>>> in strings is causing errors out of sparse.
>>>
>>> EG:
>>> drivers/md/dm.c:3813:1: error: bad constant expression
>>> drivers/md/dm.c:3814:1: error: bad constant expression
>>> drivers/md/dm.c:3816:1: error: bad constant expression
>>> drivers/md/dm.c:3817:1: error: bad constant expression
>>>
>>> I've tracked it down to the sizeof(str) - 1 == __builtin_strlen(str)
>>> failing to be a good constant expression...
>>>
>>> This is an example of the assert which isn't working:
>>>
>>> _Static_assert(sizeof("moo") - 1 == __builtin_strlen("moo"), "nul!");
>>>
>>> This does at least get past w/o warnings
>>> _Static_assert(__builtin_types_compatible_p(int, int), "doh!");
>>>
>>> I've had a go at updating builtin.c to deal with __builtin_strlen()
>>> for a string constant (attached) but that's just changing the
>>> output to "error: bad integer constant expression" so not sure
>>> what I've missed here.
>>>
>>
>> Al has a fix for that.
>> https://git.kernel.org/pub/scm/linux/kernel/git/viro/sparse.git/commit/?id=2634e39bf02697a18fece057208150362c985992
> 
> Al: Will you be contributing this fix (and perhaps the rest of your
> accumulated changes) to linux-sparse?
> 
> /jeff

And are there any other goodies in that tree?

-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

  reply	other threads:[~2026-02-10 15:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 19:41 issue with _Static_assert and __builtin()s Ben Dooks
2026-01-08  5:41 ` Dan Carpenter
2026-01-08  9:38   ` Ben Dooks
2026-02-09 16:25   ` Jeff Johnson
2026-02-10 14:25     ` Ben Dooks [this message]
2026-02-10 14:40       ` Jeff Johnson

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=1b4aab7e-28ad-4b8f-a2f4-fac639e923bb@codethink.co.uk \
    --to=ben.dooks@codethink.co.uk \
    --cc=dan.carpenter@linaro.org \
    --cc=jeff.johnson@oss.qualcomm.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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