public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/95349] Using std::launder(p) produces unexpected behavior where (p) produces expected behavior
Date: Mon, 03 Jun 2024 11:19:28 +0000	[thread overview]
Message-ID: <bug-95349-4-KABdFeDN5c@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95349-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #50 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 3 Jun 2024, Christopher.Nerz at de dot bosch.com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95349
> 
> --- Comment #49 from Christopher Nerz <Christopher.Nerz at de dot bosch.com> ---
> Ah, misunderstood and therefore forgot optimization to a constant.
> 
> In the current code example, we have the problem that the (second)
> initialization does not initialize with a value (ergo undefined behaviour due
> to uninitialized variable although it is created in an initialized memory).
> In the more complex code - which I am trying to simplify, but so far get the
> behaviour only in quite special situations which are hard to reduce to an
> example - we have that the buffer is explicitly initialized via `new T{}`
> (calling an inline initialization, i.e. not a trivial default constructor, but
> T is trivially copy & move constructible), then the buffer is copied (as
> std::byte-array) and then std::launder is applied to the resulting byte-array.
> To my understanding [basic.types.general].$3
> 
> > For two distinct objects obj1 and obj2 of trivially copyable type T, where neither obj1 nor obj2 is a potentially-overlapping subobject, if the underlying bytes (6.7.1) making up obj1 are copied into obj2, obj2 shall subsequently hold the same value as obj1.
> 
> guarantees that the copied buffer can be used as `T` via
> `*std::launder<T*>(second_buffer)`. Clang, MSVC agree, gcc does not.
> 
> Again: Still trying to construct the minimal example for that behavior :-/

Hmm, copying as std::byte-array should make the store use alias-set zero
so a followup load as T should be OK.  Unless "then the buffer is copied 
(as std::byte-array)" is really doing something more advanced with regard
to type-based aliasing rules (thus not a plain memcpy).

  parent reply	other threads:[~2024-06-03 11:19 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 20:45 [Bug c++/95349] New: " andrew2085 at gmail dot com
2020-05-27  8:04 ` [Bug c++/95349] " rguenth at gcc dot gnu.org
2020-05-27  9:14 ` redi at gcc dot gnu.org
2020-05-27  9:40 ` rguenther at suse dot de
2020-05-27 11:05 ` redi at gcc dot gnu.org
2020-05-27 14:45 ` andrew2085 at gmail dot com
2020-05-27 15:07 ` redi at gcc dot gnu.org
2020-05-27 15:19 ` andrew2085 at gmail dot com
2020-05-27 16:01 ` andrew2085 at gmail dot com
2020-05-29 10:59 ` ed at catmur dot uk
2020-05-29 11:23 ` rguenth at gcc dot gnu.org
2020-05-29 11:32 ` rguenth at gcc dot gnu.org
2020-05-29 13:53 ` ed at catmur dot uk
2020-05-29 14:15 ` redi at gcc dot gnu.org
2020-05-29 14:24 ` rguenther at suse dot de
2020-05-29 15:05 ` andrew2085 at gmail dot com
2020-05-29 18:07 ` richard-gccbugzilla at metafoo dot co.uk
2020-05-29 21:00 ` andrew2085 at gmail dot com
2020-05-29 21:50 ` richard-gccbugzilla at metafoo dot co.uk
2020-05-29 23:13 ` andrew2085 at gmail dot com
2020-05-29 23:25 ` richard-gccbugzilla at metafoo dot co.uk
2020-06-02 12:09 ` rguenth at gcc dot gnu.org
2020-06-02 12:20 ` rguenth at gcc dot gnu.org
2020-06-02 16:00 ` andrew2085 at gmail dot com
2020-06-02 16:23 ` rguenther at suse dot de
2020-06-02 16:34 ` andrew2085 at gmail dot com
2020-06-02 16:37 ` andrew2085 at gmail dot com
2020-06-02 17:54 ` rguenther at suse dot de
2020-06-02 18:43 ` andrew2085 at gmail dot com
2020-06-02 20:53 ` andrew2085 at gmail dot com
2020-06-03  6:52 ` rguenth at gcc dot gnu.org
2020-06-04  0:27 ` andrew2085 at gmail dot com
2020-06-04  6:14 ` rguenther at suse dot de
2020-06-04 16:05 ` andrew2085 at gmail dot com
2020-06-05  6:52 ` rguenth at gcc dot gnu.org
2020-06-05 14:30 ` andrew2085 at gmail dot com
2020-06-15  9:29 ` rguenth at gcc dot gnu.org
2020-06-15 21:45 ` richard-gccbugzilla at metafoo dot co.uk
2020-06-16  3:27 ` andrew2085 at gmail dot com
2020-06-16  6:50 ` rguenther at suse dot de
2020-06-16  6:57 ` rguenther at suse dot de
2020-06-16 13:56 ` andrew2085 at gmail dot com
2022-01-11 12:43 ` rguenth at gcc dot gnu.org
2022-01-11 12:48 ` rguenth at gcc dot gnu.org
2022-11-14  4:53 ` andrew2085 at gmail dot com
2024-06-03  8:02 ` Christopher.Nerz at de dot bosch.com
2024-06-03  8:51 ` rguenth at gcc dot gnu.org
2024-06-03  9:13 ` Christopher.Nerz at de dot bosch.com
2024-06-03  9:23 ` rguenth at gcc dot gnu.org
2024-06-03 10:26 ` Christopher.Nerz at de dot bosch.com
2024-06-03 11:19 ` rguenther at suse dot de [this message]
2024-06-03 15:53 ` redi at gcc dot gnu.org
2024-06-03 16:00 ` redi at gcc dot gnu.org

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-95349-4-KABdFeDN5c@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).