[llvm-bugs] [Bug 31829] New: clang -Wuninitialized annoying false positive

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 31 13:11:14 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31829

            Bug ID: 31829
           Summary: clang -Wuninitialized annoying false positive
           Product: new-bugs
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: arnd at linaro.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

A common construct from the Linux kernel causes many false positive warnings at
the default warning level. The test case is mostly reduced but kept to look
like kernel code for clarity:

$ clang -c test.c
test.c:31:29: warning: variable 'c' is uninitialized when used within its own
initialization [-Wuninitialized]
        DECLARE_COMPLETION_ONSTACK(c);
                                   ^
test.c:17:65: note: expanded from macro 'DECLARE_COMPLETION_ONSTACK'
        struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
                          ~~~~                                  ^~~~
test.c:14:36: note: expanded from macro 'COMPLETION_INITIALIZER_ONSTACK'
        ({ init_completion(&work); work; })
                                   ^~~~
1 warning generated.
$ gcc -Wall -Wextra -Wuninitialized -O2  -c test.c # no output
$ cat test.c
struct __wait_queue_head {
        int              lock;
};
typedef struct __wait_queue_head wait_queue_head_t;
struct completion {
        unsigned int done;
        wait_queue_head_t wait;
};
#define COMPLETION_INITIALIZER_ONSTACK(work) \
        ({ init_completion(&work); work; })
#define DECLARE_COMPLETION_ONSTACK(work) \
        struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
extern void init_waitqueue_head(wait_queue_head_t *);
static inline void init_completion(struct completion *x)
{
        x->done = 0;
        init_waitqueue_head(&x->wait);
}
extern int f2(struct completion *);
int f1(void)
{
    DECLARE_COMPLETION_ONSTACK(c);

    return f2(&c);
}

There seems to be a special case for detecting "self-assignment in declaration"
in clang, which is usually a bug, but this specific construct is clearly
correct, as we do initialize the variable immediately before using it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170131/00b29b6c/attachment.html>


More information about the llvm-bugs mailing list