diff mbox series

[v2,07/10] selftests/nolibc: avoid unused arguments warnings

Message ID 20230801-nolibc-warnings-v2-7-1ba5ca57bd9b@weissschuh.net (mailing list archive)
State New
Headers show
Series tools/nolibc: enable compiler warnings | expand

Commit Message

Thomas Weißschuh Aug. 1, 2023, 5:30 a.m. UTC
This warnings will be enabled later so avoid triggering it.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Willy Tarreau Aug. 1, 2023, 8:07 a.m. UTC | #1
On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote:
> This warnings will be enabled later so avoid triggering it.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 53a3773c7790..cb17cccd0bc7 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -1089,7 +1089,8 @@ static int smash_stack(void)
>  	return 1;
>  }
>  
> -static int run_protection(int min, int max)
> +static int run_protection(int __attribute__((unused)) min,
> +			  int __attribute__((unused)) max)

This one is used to silence -Wunused-parameter I guess. It's one of
the rare warnings that I find totally useless in field, because it's
simply against the principle of using function pointers with different
functions having the same interface but different implementations. As
your code evolves you end up with unused on absolutely *all* of the
arguments of *all* such functions, which makes them a real pain to add
and tends to encourage poor practices such as excessive code reuse just
by laziness or boredom. BTW it's one of those that are already disabled
in the kernel and we could very well do the same here.

Willy
Thomas Weißschuh Aug. 1, 2023, 8:13 a.m. UTC | #2
On 2023-08-01 10:07:28+0200, Willy Tarreau wrote:
> On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote:
> > This warnings will be enabled later so avoid triggering it.
> > 
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 53a3773c7790..cb17cccd0bc7 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -1089,7 +1089,8 @@ static int smash_stack(void)
> >  	return 1;
> >  }
> >  
> > -static int run_protection(int min, int max)
> > +static int run_protection(int __attribute__((unused)) min,
> > +			  int __attribute__((unused)) max)
> 
> This one is used to silence -Wunused-parameter I guess.

Yep.

> It's one of
> the rare warnings that I find totally useless in field, because it's
> simply against the principle of using function pointers with different
> functions having the same interface but different implementations. As
> your code evolves you end up with unused on absolutely *all* of the
> arguments of *all* such functions, which makes them a real pain to add
> and tends to encourage poor practices such as excessive code reuse just
> by laziness or boredom. BTW it's one of those that are already disabled
> in the kernel and we could very well do the same here.

It's indeed unfortunate.

As long as we don't have too many of them I would prefer to keep the
explicit annotations. While they are ugly we then can still reap the
positive aspects of the warning.

This is where -std=c89 bites us. With extensions (or C2X) we could also
just leave off the argument name to mark it as unused:
    run_protection(int, int)
Zhangjin Wu Aug. 1, 2023, 10:15 a.m. UTC | #3
Hi, Thomas

> On 2023-08-01 10:07:28+0200, Willy Tarreau wrote:
> > On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote:
> > > This warnings will be enabled later so avoid triggering it.
> > > 
> > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > ---
> > >  tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > index 53a3773c7790..cb17cccd0bc7 100644
> > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > @@ -1089,7 +1089,8 @@ static int smash_stack(void)
> > >  	return 1;
> > >  }
> > >  
> > > -static int run_protection(int min, int max)
> > > +static int run_protection(int __attribute__((unused)) min,
> > > +			  int __attribute__((unused)) max)
> > 
> > This one is used to silence -Wunused-parameter I guess.
> 
> Yep.
> 
> > It's one of
> > the rare warnings that I find totally useless in field, because it's
> > simply against the principle of using function pointers with different
> > functions having the same interface but different implementations. As
> > your code evolves you end up with unused on absolutely *all* of the
> > arguments of *all* such functions, which makes them a real pain to add
> > and tends to encourage poor practices such as excessive code reuse just
> > by laziness or boredom. BTW it's one of those that are already disabled
> > in the kernel and we could very well do the same here.
> 
> It's indeed unfortunate.
> 
> As long as we don't have too many of them I would prefer to keep the
> explicit annotations. While they are ugly we then can still reap the
> positive aspects of the warning.
> 
> This is where -std=c89 bites us. With extensions (or C2X) we could also
> just leave off the argument name to mark it as unused:
>     run_protection(int, int)

what about further simply ignore the arguments like we did for main(void)?

Thanks,
Zhangjin
Thomas Weißschuh Aug. 1, 2023, 10:17 a.m. UTC | #4
Aug 1, 2023 12:15:27 Zhangjin Wu <falcon@tinylab.org>:

> Hi, Thomas
>
>> On 2023-08-01 10:07:28+0200, Willy Tarreau wrote:
>>> On Tue, Aug 01, 2023 at 07:30:14AM +0200, Thomas Weißschuh wrote:
>>>> This warnings will be enabled later so avoid triggering it.
>>>>
>>>> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
>>>> ---
>>>> tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
>>>> index 53a3773c7790..cb17cccd0bc7 100644
>>>> --- a/tools/testing/selftests/nolibc/nolibc-test.c
>>>> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
>>>> @@ -1089,7 +1089,8 @@ static int smash_stack(void)
>>>>     return 1;
>>>> }
>>>>
>>>> -static int run_protection(int min, int max)
>>>> +static int run_protection(int __attribute__((unused)) min,
>>>> +             int __attribute__((unused)) max)
>>>
>>> This one is used to silence -Wunused-parameter I guess.
>>
>> Yep.
>>
>>> It's one of
>>> the rare warnings that I find totally useless in field, because it's
>>> simply against the principle of using function pointers with different
>>> functions having the same interface but different implementations. As
>>> your code evolves you end up with unused on absolutely *all* of the
>>> arguments of *all* such functions, which makes them a real pain to add
>>> and tends to encourage poor practices such as excessive code reuse just
>>> by laziness or boredom. BTW it's one of those that are already disabled
>>> in the kernel and we could very well do the same here.
>>
>> It's indeed unfortunate.
>>
>> As long as we don't have too many of them I would prefer to keep the
>> explicit annotations. While they are ugly we then can still reap the
>> positive aspects of the warning.
>>
>> This is where -std=c89 bites us. With extensions (or C2X) we could also
>> just leave off the argument name to mark it as unused:
>>     run_protection(int, int)
>
> what about further simply ignore the arguments like we did for main(void)?

That doesn't work because it is stored as a function pointer in the testcases array.
And these members all take the two parameters.
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 53a3773c7790..cb17cccd0bc7 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1089,7 +1089,8 @@  static int smash_stack(void)
 	return 1;
 }
 
-static int run_protection(int min, int max)
+static int run_protection(int __attribute__((unused)) min,
+			  int __attribute__((unused)) max)
 {
 	pid_t pid;
 	int llen = 0, status;