public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "xry111 at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/113025] Pointer is sometimes assumed to be 16-byte aligned even when there is no such guarantee
Date: Mon, 18 Dec 2023 21:14:32 +0000	[thread overview]
Message-ID: <bug-113025-4-8ATmoZ6MbJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113025-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #3)
> (In reply to juki from comment #2)
> > Unfortunately alignment of the cast type was not causing this issue.
> > 
> > I changed all calls that were defined in GCC headers to use __m128i_u or
> > __m128d_u types to use those types before unaligned intrinsic.
> > 
> > For example LOAD_SI128 macro looks like the following:
> > 
> > #define LOAD_SI128(ptr) \
> >         ( ((uintptr_t)(ptr) & 15) == 0 ) ? _mm_load_si128((__m128i*)(ptr)) :
> > _mm_loadu_si128((__m128i_u*)(ptr))
> 
> This won't work if ptr is a __m128i *.  It is allowed to optimize
> (uintptr_t)(__m128i *)foo % 15 to 0 because the standard says (__m128i *)foo

I mean % 16, not % 15.

> invokes undefined behavior when foo is a pointer not aligned to 16-byte
> boundary (C23 section 6.3.2.3p6).

  parent reply	other threads:[~2023-12-18 21:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 21:39 [Bug c++/113025] New: " juki at gcc dot mail.kapsi.fi
2023-12-14 21:44 ` [Bug c++/113025] " pinskia at gcc dot gnu.org
2023-12-18 17:10 ` juki at gcc dot mail.kapsi.fi
2023-12-18 17:13 ` pinskia at gcc dot gnu.org
2023-12-18 21:14 ` xry111 at gcc dot gnu.org
2023-12-18 21:14 ` xry111 at gcc dot gnu.org [this message]
2023-12-18 21:30 ` juki at gcc dot mail.kapsi.fi
2023-12-18 21:41 ` xry111 at gcc dot gnu.org
2023-12-18 22:01 ` juki at gcc dot mail.kapsi.fi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113025-4-8ATmoZ6MbJ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).