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 tree-optimization/101061] tree-vrp misoptimization on skylake+ using union-based aliasing Date: Wed, 16 Jun 2021 11:10:12 +0000 [thread overview] Message-ID: <bug-101061-4-j3sSQ1tLaV@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-101061-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101061 --- Comment #14 from rguenther at suse dot de <rguenther at suse dot de> --- On Wed, 16 Jun 2021, alexander.grund@tu-dresden.de wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101061 > > --- Comment #13 from Alexander Grund <alexander.grund@tu-dresden.de> --- > > But what you can see is that the resulting pointer is used for the initialization and not the placement address as literally written in source. > > So I assume it was supposed to be "Y::Y (D_6557, 1);" ? > > > I'm not sure how one can solve this issue with using placement new > > but are unions not sufficiently restricted so that copy assignment > > should work (and activate the appropriate union member)? Thus > > > > slot->mutable_value = pair<const K, V>(k, v); > > The problem is not the copy, the problem is that the value may contain any kind > of data, think e.g. a pair of strings. And at the initial point (i.e. first > emplace) the slot is a casted pointer into uninitialized data. I.e. the above > would be an assignment into an object which does not exist. And (especially) > for such non-trivial types this would break. > > I think it will work for trivial types though, although it is UB due to > lifetime rules: You can't use an object (here: assign to) which has not started > its lifetime yet. I see. I would need to read up what kind of restrictions recent C++ standards place on union members, but in C a store to a non-active union member makes that active and IIRC for tradidional POD data types the same should hold true for C++, even w/o requiring an explicit placement new. > However e.g. pair has custom copy and regular constructors so I think it will > run into the issue you mentioned: The ctor will access the object via the > this-pointer and not via the full union-thing and hence might misoptimise later > > This would mean that in conclusion the use case of putting std::pairs in an > union and accessing them via aliasing is unsupported by (at least) GCC. Is that > correct? Without restricting the set of C++ features used, yes. Even accessing the data via union.memb.getX (); would involve a 'this' pointer and thus break things. std::pair is probably a special-case that might work since you use pair.first rather than a method though ;) You can see this type-punning via unions exception was invented for C ;)
next prev parent reply other threads:[~2021-06-16 11:10 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-14 10:39 [Bug tree-optimization/101061] New: " alexander.grund@tu-dresden.de 2021-06-14 10:40 ` [Bug tree-optimization/101061] " alexander.grund@tu-dresden.de 2021-06-15 7:31 ` rguenth at gcc dot gnu.org 2021-06-15 12:51 ` alexander.grund@tu-dresden.de 2021-06-15 13:02 ` rguenther at suse dot de 2021-06-15 14:21 ` alexander.grund@tu-dresden.de 2021-06-15 14:27 ` alexander.grund@tu-dresden.de 2021-06-15 16:16 ` rguenther at suse dot de 2021-06-15 16:20 ` rguenther at suse dot de 2021-06-16 6:23 ` alexander.grund@tu-dresden.de 2021-06-16 7:34 ` alexander.grund@tu-dresden.de 2021-06-16 9:46 ` rguenther at suse dot de 2021-06-16 9:54 ` rguenther at suse dot de 2021-06-16 10:11 ` alexander.grund@tu-dresden.de 2021-06-16 11:10 ` rguenther at suse dot de [this message] 2021-06-24 7:09 ` rguenth 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-101061-4-j3sSQ1tLaV@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: linkBe 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).