<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 --- - No strict aliasing for uint8_t"
   href="https://llvm.org/bugs/show_bug.cgi?id=31410">31410</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>No strict aliasing for uint8_t
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rsilvera@google.com
          </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>Currently uint8_t is treated identically to an unsigned char for purposes
of strict aliasing. This is unnecessary and results in missed optimization,
since unsigned chars must alias all other types (but uint8_ts are not required
to).

There is a related discussion at
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110</a>

Here is a trivial demonstration:

#include <stdint.h>

int strict(uint32_t *p, uint8_t *q) {
  *p = 1;
  *q = 0;
  return *p;
}

With clang -O on x86-64, we get:
        mov     dword ptr [rdi], 1
        mov     byte ptr [rsi], 0
        mov     eax, dword ptr [rdi]
        ret

Replacing uint8_t with uint16_t (note the load immediate into eax):
        mov     dword ptr [rdi], 1
        mov     word ptr [rsi], 0
        mov     eax, 1
        ret</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>