Re: [PATCH] waitqueue: fix clang -Wuninitialized warnings

From: Nick Desaulniers
Date: Fri Jul 12 2019 - 12:48:23 EST


On Fri, Jul 12, 2019 at 12:45 AM Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> On Fri, Jul 12, 2019 at 2:49 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> > On Wed, 3 Jul 2019 10:10:55 +0200 Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> > <scratches head>
> >
> > Surely clang is being extraordinarily dumb here?
> >
> > DECLARE_WAIT_QUEUE_HEAD_ONSTACK() is effectively doing
> >
> > struct wait_queue_head name = ({ __init_waitqueue_head(&name) ; name; })
> >
> > which is perfectly legitimate! clang has no business assuming that
> > __init_waitqueue_head() will do any reads from the pointer which it was
> > passed, nor can clang assume that __init_waitqueue_head() leaves any of
> > *name uninitialized.
> >
> > Does it also warn if code does this?
> >
> > struct wait_queue_head name;
> > __init_waitqueue_head(&name);
> > name = name;
> >
> > which is equivalent, isn't it?
>
> No, it does not warn for this.

So I think this is just a bug in Clang, where it's getting tripped up
due to the GNU C statement expression. See the example I put in this
bug report: https://bugs.llvm.org/show_bug.cgi?id=42604

Clang is warning for this pattern of struct assignment, but not for
non-aggregate (integral) assignment.

(I think that pattern is pretty cool; it makes it more straightforward
to provide macro's that properly construct aggregates in C; in
particular I feel like I've been looking for something like this to
simply the use of __attribute__((__cleanup__)) to do RAII in C and
make smart pointers, fd's, etc.).

Let's fix Clang, drop the kernel workaround, and thanks for the discussion.
--
Thanks,
~Nick Desaulniers