* linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
@ 2024-09-30 13:49 David Binderman
2024-09-30 13:58 ` Javier Carrasco
2024-09-30 14:19 ` Lars-Peter Clausen
0 siblings, 2 replies; 10+ messages in thread
From: David Binderman @ 2024-09-30 13:49 UTC (permalink / raw)
To: jagathjog1996@gmail.com, jic23@kernel.org, lars@metafoo.de,
linux-iio@vger.kernel.org, Linux Kernel Mailing List
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
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 14:19 ` Lars-Peter Clausen
1 sibling, 2 replies; 10+ messages in thread
From: Javier Carrasco @ 2024-09-30 13:58 UTC (permalink / raw)
To: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
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?
Best regards,
Javier Carrasco
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 13:58 ` Javier Carrasco
@ 2024-09-30 14:04 ` Javier Carrasco
2024-09-30 15:15 ` Nathan Chancellor
1 sibling, 0 replies; 10+ messages in thread
From: Javier Carrasco @ 2024-09-30 14:04 UTC (permalink / raw)
To: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
On 30/09/2024 15:58, 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
bmi323_reg_savestate :)
> that one is used beyond ARRAY_SIZE.
>
> Safe to ignore?
>
> Best regards,
> Javier Carrasco
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
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:19 ` Lars-Peter Clausen
2024-09-30 14:47 ` Jonathan Cameron
2024-09-30 14:47 ` Denis Benato
1 sibling, 2 replies; 10+ messages in thread
From: Lars-Peter Clausen @ 2024-09-30 14:19 UTC (permalink / raw)
To: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
linux-iio@vger.kernel.org, Linux Kernel Mailing List
On 9/30/24 06: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 ?
Yes. Do you want to send a fix?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 14:19 ` Lars-Peter Clausen
@ 2024-09-30 14:47 ` Jonathan Cameron
2024-09-30 14:47 ` Denis Benato
1 sibling, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2024-09-30 14:47 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
linux-iio@vger.kernel.org, Linux Kernel Mailing List
On Mon, 30 Sep 2024 07:19:14 -0700
Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 9/30/24 06: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 ?
> Yes. Do you want to send a fix?
>
Have a couple of fixes queued for this driver (including I Think this one).
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=fixes-togreg&id=506a1ac4c4464a61e4336e135841067dbc040aaa
I'm just letting the fixes sit in next for a day or two to make sure nothing
else shows up then I'll do a pull request.
Jonathan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 14:19 ` Lars-Peter Clausen
2024-09-30 14:47 ` Jonathan Cameron
@ 2024-09-30 14:47 ` Denis Benato
1 sibling, 0 replies; 10+ messages in thread
From: Denis Benato @ 2024-09-30 14:47 UTC (permalink / raw)
To: Lars-Peter Clausen, David Binderman, jagathjog1996@gmail.com,
jic23@kernel.org, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
Il 30 settembre 2024 16:19:14 CEST, Lars-Peter Clausen <lars@metafoo.de> ha scritto:
>On 9/30/24 06: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 ?
>Yes. Do you want to send a fix?
>
Hello,
I think fixes are pending already in one of Jonathan Cameron's branches.
Best regards,
Denis Benato
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
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
1 sibling, 1 reply; 10+ messages in thread
From: Nathan Chancellor @ 2024-09-30 15:15 UTC (permalink / raw)
To: Javier Carrasco
Cc: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 15:15 ` Nathan Chancellor
@ 2024-09-30 16:50 ` Javier Carrasco
2024-09-30 20:26 ` Nathan Chancellor
0 siblings, 1 reply; 10+ messages in thread
From: Javier Carrasco @ 2024-09-30 16:50 UTC (permalink / raw)
To: Nathan Chancellor
Cc: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
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!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 16:50 ` Javier Carrasco
@ 2024-09-30 20:26 ` Nathan Chancellor
2024-09-30 20:46 ` Javier Carrasco
0 siblings, 1 reply; 10+ messages in thread
From: Nathan Chancellor @ 2024-09-30 20:26 UTC (permalink / raw)
To: Javier Carrasco
Cc: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
Hi Javier,
On Mon, Sep 30, 2024 at 06:50:14PM +0200, Javier Carrasco wrote:
> 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?
Correct.
> Is it then just to silence the warning, or does it have other
> implications? Thanks again!
Yes, the use of the unused attribute would just be to silence the
warning; the variable would still not be emitted in the final binary.
clang's behavior matches GCC's (aside from the special warning):
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-unused-variable-attribute
If the variable needed to be emitted in the object file,
__attribute__((used)) would need to be used, which explicitly has code
generation implications:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-used-variable-attribute
A contrived example:
https://godbolt.org/z/oGGbqK98o
Cheers,
Nathan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: linux-6.12-rc1/drivers/iio/imu/bmi323/bmi323_core.c:133: Array contents defined but not used ?
2024-09-30 20:26 ` Nathan Chancellor
@ 2024-09-30 20:46 ` Javier Carrasco
0 siblings, 0 replies; 10+ messages in thread
From: Javier Carrasco @ 2024-09-30 20:46 UTC (permalink / raw)
To: Nathan Chancellor
Cc: David Binderman, jagathjog1996@gmail.com, jic23@kernel.org,
lars@metafoo.de, linux-iio@vger.kernel.org,
Linux Kernel Mailing List
On 30/09/2024 22:26, Nathan Chancellor wrote:
> Hi Javier,
>
> On Mon, Sep 30, 2024 at 06:50:14PM +0200, Javier Carrasco wrote:
>> 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?
>
> Correct.
>
>> Is it then just to silence the warning, or does it have other
>> implications? Thanks again!
>
> Yes, the use of the unused attribute would just be to silence the
> warning; the variable would still not be emitted in the final binary.
> clang's behavior matches GCC's (aside from the special warning):
>
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-unused-variable-attribute
>
> If the variable needed to be emitted in the object file,
> __attribute__((used)) would need to be used, which explicitly has code
> generation implications:
>
> https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-used-variable-attribute
>
> A contrived example:
>
> https://godbolt.org/z/oGGbqK98o
>
> Cheers,
> Nathan
Thanks a lot for spoon-feeding it to me :)
Best regards,
Javier Carrasco
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-09-30 20:46 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox