<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 --- - False positive (divide by zero), involving ALIGNOF()" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23893&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=rszuyExV_blTn5EjLoiob0DuBerTQLAVT27Y6B7o3xg&s=jpcyAJh8w43aO3IjF24LuOfdTv1bRyr1pANBnIUbQeM&e=">23893</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive (divide by zero), involving ALIGNOF()
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </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>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arnsholt@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the MoarVM project, we have some code that looks like this (computing
offsets for struct members):

    size_t cur_size;
    size_t align = ALIGNOF(void *);
    /* Stuff we don't care about here, setting cur_size */
    if (cur_size % align)
        cur_size += align - cur_size % align;

The static analyzer thinks that `align` is initialized to 0 and thus that
there's a potential divide-by-zero in the modulo operation. This is clearly not
possible, since the smallest possible ALIGNOF value is 1.

Our ALIGNOF is implemented like this:

    #define ALIGNOF(t) ((char *)(&((struct { char c; t _h; } *)0)->_h) - (char
*)0)</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>