Re: sparse: __pure declaration only

From: Luc Van Oostenryck
Date: Sun Oct 20 2019 - 01:53:13 EST


On Fri, Oct 18, 2019 at 08:31:48AM -0700, Linus Torvalds wrote:
> On Fri, Oct 18, 2019 at 4:15 AM Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx> wrote:
> >
> > is this a valid warning? if not, should sparse be ignoring these.
>
> It's technically valid, but maybe it's not useful.
>
> If we make sure that any pure bits from a declaration always make it
> into the definition, then I suspect that the "was not declared"
> warning (if the definition is non-static and seen without a
> declaration) is sufficient.
>
> Of course, sparse doesn't actually _care_ about "pure" in the
> definition, only in the use, so right now it doesn't even make any
> difference to sparse whether the definition has the "pure" or not.
> It's only when the function is used that the "pure" matters (it makes
> the call instruction be CSE'd like any other random instruction).

Yes, for 'pure' it doesn't matter much but it's a problem anyway.
For example with 'static':

$ cat file.c
static void foo(void);
void foo(void) { }

$ sparse file.c
file.c:2:6: warning: symbol 'foo' was not declared. Should it be static?

Which is kinda absurd: foo() was declared and was even declared static.
But the definition is a different symbol than its declaration (OK) which
doesn't 'inherit' the declaration's specifier/modifier/attributes.
It's on my to-be-fixed list for a long time but ..

-- Luc