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: unassignedclangb...@nondot.org
          Reporter: rsilv...@google.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to