From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: David Binderman <dcb314@hotmail.com>,
"jagathjog1996@gmail.com" <jagathjog1996@gmail.com>,
"jic23@kernel.org" <jic23@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
Date: Mon, 30 Sep 2024 18:50:14 +0200 [thread overview]
Message-ID: <0342111e-47f7-4981-a1f1-e694392fa741@gmail.com> (raw)
In-Reply-To: <20240930151542.GA3556370@thelio-3990X>
On 30/09/2024 17:15, Nathan Chancellor wrote:
> On Mon, Sep 30, 2024 at 03:58:06PM +0200, Javier Carrasco wrote:
>> On 30/09/2024 15:49, David Binderman wrote:
>>> Hello there,
>>>
>>> I just tried to build linux-6.12-rc1 with clang. It said:
>>>
>>> drivers/iio/imu/bmi323/bmi323_core.c:133:27: warning: variable 'bmi323_ext_reg_savestate' is not needed and will not be emitted [-Wunneeded-internal-declaration]
>>>
>>> A grep for the identifier shows the following strange results::
>>>
>>> inux-6.12-rc1 $ grep bmi323_ext_reg_savestate drivers/iio/imu/bmi323/bmi323_core.c
>>> static const unsigned int bmi323_ext_reg_savestate[] = {
>>> unsigned int ext_reg_settings[ARRAY_SIZE(bmi323_ext_reg_savestate)];
>>> for (unsigned int i = 0; i < ARRAY_SIZE(bmi323_ext_reg_savestate); i++) {
>>> for (unsigned int i = 0; i < ARRAY_SIZE(bmi323_ext_reg_savestate); i++) {
>>> linux-6.12-rc1 $
>>>
>>> I see no mention of bmi323_ext_reg_savestate[ i]. Is there a possible
>>> cut'n'paste error in one of the two for loops ?
>>>
>>> Regards
>>>
>>> David Binderman
>>
>>
>> I think that is a bug in clang:
>>
>> https://bugs.llvm.org/show_bug.cgi?id=33068
>>
>> That happens because clang sees that bmi323_ext_reg_savestate is not
>> used but to gets its size, and that means for it that the variable is
>> not needed. That does not happen for example with
>> bmi323_ext_reg_savestate (right above bmi323_ext_reg_savestate) because
>> that one is used beyond ARRAY_SIZE.
>>
>> Safe to ignore?
>
> As later comments in this thread point out, this is a bug in the code:
>
> https://git.kernel.org/jic23/iio/c/506a1ac4c4464a61e4336e135841067dbc040aaa
>
> That bug report is pretty misguided, as that is exactly the type of code
> that warning tries to catch: the programmer has a static variable that
> is only used in sizeof(), a compile time evaluation, so they won't get a
> -Wunused-variable since it is used in that expression, but did they
> intend to use it elsewhere? If they didn't, they can just slap
> '__maybe_unused' / '__attribute__((unused))' on it or use
> sizeof(<type>), which removes all ambiguity. Otherwise, the code should
> be fixed, like in this case.
>
> Cheers,
> Nathan
@Nathan thanks for the clarification.
So in this case, the array should have been used not only to get its size.
But if that wasn't the case, and since you can't use sizeof(<type>),
should it be marked with __maybe_unused / __attribute__((unused)) even
though it's known in advance that it won't be used, or at least that its
use will be to get its size? Is it then just to silence the warning, or
does it have other implications? Thanks again!
next prev parent reply other threads:[~2024-09-30 16:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 13:49 linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ? David Binderman
2024-09-30 13:58 ` Javier Carrasco
2024-09-30 14:04 ` Javier Carrasco
2024-09-30 15:15 ` Nathan Chancellor
2024-09-30 16:50 ` Javier Carrasco [this message]
2024-09-30 20:26 ` Nathan Chancellor
2024-09-30 20:46 ` Javier Carrasco
2024-09-30 14:19 ` Lars-Peter Clausen
2024-09-30 14:47 ` Jonathan Cameron
2024-09-30 14:47 ` Denis Benato
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=0342111e-47f7-4981-a1f1-e694392fa741@gmail.com \
--to=javier.carrasco.cruz@gmail.com \
--cc=dcb314@hotmail.com \
--cc=jagathjog1996@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@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