Bug 70118 - UBSan claims misaligned access in SSE instrinsics
Summary: UBSan claims misaligned access in SSE instrinsics
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic, wrong-code
Depends on: 80799
  Show dependency treegraph
Reported: 2016-03-07 10:20 UTC by Allan Jensen
Modified: 2017-05-17 21:16 UTC (History)
3 users (show)

See Also:
Target: x86_64-*-*, i?86-*-*
Known to work:
Known to fail:
Last reconfirmed: 2016-03-07 00:00:00

Proposed patch (315 bytes, patch)
2016-11-23 14:14 UTC, Allan Jensen
Details | Diff
Patch (509 bytes, patch)
2016-11-24 13:46 UTC, Allan Jensen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Jensen 2016-03-07 10:20:24 UTC
The intrinsics _mm_loadl_epi64 and _mm_storel_epi64 triggers UBSan warnings on unaligned access because the instrinsics definitions in emmintrin.h are using __m64 and __v2di pointers, and both those types have been declared with default alignment. The intrinsics definitions should probably either be replaced with a __builtin_ia32_movq, or the __m64 and __v2di types be defined with __attribute__ ((aligned(1))).
Comment 1 marc 2016-03-07 10:40:27 UTC
Confirmed on gcc version 6.0.0 20160304
Comment 2 Allan Jensen 2016-11-23 13:49:53 UTC
I believe this to be fixed by r239889
Comment 3 Allan Jensen 2016-11-23 13:57:39 UTC
Or r217608
Comment 4 Allan Jensen 2016-11-23 14:14:29 UTC
Created attachment 40130 [details]
Proposed patch

On closer inspection, we are only almost there, two minor changes are still needed. (testing patch).
Comment 5 Allan Jensen 2016-11-24 13:46:18 UTC
Created attachment 40140 [details]

Updated patch confirmed to work
Comment 6 uros 2016-12-11 16:27:40 UTC
Author: uros
Date: Sun Dec 11 16:27:08 2016
New Revision: 243527

URL: https://gcc.gnu.org/viewcvs?rev=243527&root=gcc&view=rev
	PR target/70118
	* config/i386/mmintrin.h (__m64_u): New type
	* config/i386/emmintrin.h (_mm_loadl_epi64, _mm_storel_epi64):
	Make the allowed unaligned memory access explicit.

Comment 7 Allan Jensen 2016-12-12 21:40:08 UTC
Fixed in trunk