<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 - Analyzer fails to recognize C-style union struct initialization"
   href="https://bugs.llvm.org/show_bug.cgi?id=39884">39884</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Analyzer fails to recognize C-style union struct initialization
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </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>Static Analyzer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>renat@idrisov.info
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi All,
I run analysis on a piece of code with:

$ clang-tidy tidy-minimal.c -checks=* --

Code:

#include <stdio.h>
#include <stdlib.h>

struct a {
  union {
    struct {
      void *b;
    };
  };
};

void *something();
void something_else(struct a *param);

void myfunction() {
  struct a c = { .b = malloc(256) };
  something_else(&c);
}

int main() {
  myfunction();
}

----------------
I get:
/.../tidy-minimal.c:18:1: warning: Potential memory leak
[clang-analyzer-unix.Malloc]
}
^
/.../tidy-minimal.c:21:3: note: Calling 'myfunction'
  myfunction();
  ^
/.../tidy-minimal.c:16:23: note: Memory is allocated
  struct a c = { .b = malloc(256) };
                      ^
/.../tidy-minimal.c:18:1: note: Potential memory leak
}
^
----------------

It looks like it is not handling struct initialization properly because if I
remove union -- it produces no warnings

The issue could be related to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - core.CallAndMessage false positives with anonymous unions"
   href="show_bug.cgi?id=35882">https://bugs.llvm.org/show_bug.cgi?id=35882</a>
but in my case giving union a name does not resolve it.

Thanks!</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>