<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - -Wconditional-uninitialized false positive on struct array field"
   href="https://bugs.llvm.org/show_bug.cgi?id=38856">38856</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wconditional-uninitialized false positive on struct array field
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>evan.j.pretti@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20850" name="attach_20850" title="test.c">attachment 20850</a> <a href="attachment.cgi?id=20850&action=edit" title="test.c">[details]</a></span>
test.c

I have attached a case highlighting some strange behavior regarding
-Wconditional-uninitialized.

----- test.c -----
#include <stdio.h>

typedef struct { int x[2]; } test_t;

test_t foo_1(void);
test_t foo_2(void);
test_t foo_3(void);

test_t foo_1() {
    test_t t;
    for(int i = 0; i < 2; i++) t.x[i] = 0;
    return t;
}
test_t foo_2() {
    test_t t;
    t.x[0] = 0;
    for(int i = 0; i < 2; i++) t.x[i] = 0;
    return t;
}
test_t foo_3() {
    test_t t;
    t.x[0] = 0;
    return t;
}

int main() {
    test_t t;

    t = foo_1();
    printf("%i %i\n", t.x[0], t.x[1]);
    t = foo_2();
    printf("%i %i\n", t.x[0], t.x[1]);
    t = foo_3();
    printf("%i %i\n", t.x[0], t.x[1]);
}
------------------

Compilation gives:

------------------
$ clang -Weverything test.c
test.c:12:12: warning: variable 't' may be uninitialized when used here
      [-Wconditional-uninitialized]
    return t;
           ^
test.c:10:5: note: variable 't' is declared here
    test_t t;
    ^
1 warning generated.
------------------

although both elements of the array in the struct test_t have been assigned in
foo_1() where the warning is coming from.  Manual assignment of the elements
without a loop gives no warnings.  Strangely, if the first element is set as in
foo_2() followed by the loop, there is no warning.

This is fine if false positives from -Wconditional-uninitialized are considered
to be acceptable.  However, in foo_3(), only the first element of the array is
set and there are no warnings; the second element is actually uninitialized. 
This seems like it shouldn't happen.  Is this valid/wontfix behavior or a real
problem?</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>