[llvm-bugs] [Bug 31410] New: No strict aliasing for uint8_t

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 16 11:57:04 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31410

            Bug ID: 31410
           Summary: No strict aliasing for uint8_t
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rsilvera at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161216/ce2b9539/attachment.html>


More information about the llvm-bugs mailing list