https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120799

            Bug ID: 120799
           Summary: Incorrect UBSan alignment requirements for
                    _mm_storeh_pd() and _mm_storel_pd()
           Product: gcc
           Version: 15.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: justus2510 at proton dot me
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

UBSan shows warnings for _mm_storeh_pd() and _mm_storel_pd() when using
unaligned pointers. However, as far as I know, that's perfectly legal, similar
to _mm_storel_epi64() and _mm_loadl_epi64():
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70118
The Intel manual does not mention any alignment requirements for these
instructions, and Clang UBSan doesn't seem to complain about it either.

GCC version: 15.1.1 20250425

gcc -fsanitize=undefined ubsan.c

#include <emmintrin.h>

int main()
{
    unsigned char buf[128];
    _mm_storel_pd((double *)(buf+1), _mm_set1_pd(3.14));
}

/usr/lib/gcc/x86_64-pc-linux-gnu/15.1.1/include/emmintrin.h:203:8: runtime
error: store to misaligned address 0x7ffc80e8b5a1 for type 'double', which
requires 8 byte alignment

Reply via email to