<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang -Wuninitialized annoying false positive"
   href="https://llvm.org/bugs/show_bug.cgi?id=31829">31829</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang -Wuninitialized annoying false positive
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arnd@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>