<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 - transparent union pointers not understood by static analyzer"
   href="https://bugs.llvm.org/show_bug.cgi?id=42811">42811</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>transparent union pointers not understood by static analyzer
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>8.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>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>equinox-llvm@diac24.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The static analyzer doesn't seem to understand transparent union arguments,
particularly if the union members are pointers:



struct s1 {
        int x;
};
struct s2 {
        int y;
};

union arg {
        struct s1 *s1;
        struct s2 *s2;
} __attribute__((transparent_union));

void set1(union arg arg)
{
        arg.s1->x = 0;
}

void set2(union arg arg)
{
        arg.s2->y = 0;
}

int test1(void)
{
        struct s2 s2;
        set1(&s2);
        return s2.y ? 1 : 0;
}

int test2(void)
{
        struct s2 s2;
        set2(&s2);
        return s2.y ? 1 : 0;
}



$ scan-build-8 clang-8 -c -o transp_union_sa.o transp_union_sa.c
scan-build: Using '/usr/lib/llvm-8/bin/clang' for static analysis
transp_union_sa.c:27:9: warning: Branch condition evaluates to a garbage value
        return s2.y ? 1 : 0;
               ^~~~
transp_union_sa.c:34:9: warning: Branch condition evaluates to a garbage value
        return s2.y ? 1 : 0;
               ^~~~
2 warnings generated.


Ideally, neither test1 nor test2 should generate a warning; the test1 case is
much harder to get right though since it'd need the SA to understand that the x
and y struct fields for s1 and s2 are in the same place.  test2 is much easier
and should definitely not result in a warning.


$ clang-8 --version 
clang version 8.0.1-+rc4-1 (tags/RELEASE_801/rc4)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

(Debian)</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>