public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107467] Miscompilation involing -Os , -flto and -fno-strict-aliasing
Date: Sun, 30 Oct 2022 23:36:28 +0000	[thread overview]
Message-ID: <bug-107467-4-xyB97jjQHd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107467-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a single file example which just needs -Os -flto -fno-strict-aliasing:

template <class T>
struct pair
{
    int first;
    T second;
};

template <typename C>
[[gnu::optimize("strict-aliasing")]]
bool __attribute__((noinline))
compare_pairs(const pair<C> &lhs, const pair<C> &rhs) {
  return lhs.first == rhs.first && lhs.second == rhs.second;
}

template <typename B> struct Combined {
  pair<B *> 
__attribute__((noinline)) get_const() {
    return pair<B *>{123, nullptr};
  }
[[gnu::optimize("strict-aliasing")]]
  bool 
__attribute__((noinline)) clashy() {
    return compare_pairs(get_const(), get_const());
  }
};

class SomeClass {};
class OtherClass {};

[[gnu::optimize("strict-aliasing")]]
[[gnu::used]]
void some_func() {
  Combined<SomeClass> myvar;
  __builtin_printf("%i\n", myvar.clashy());
}

[[gnu::optimize("strict-aliasing")]]
void other_func() {
  Combined<OtherClass> myvar;
  __builtin_printf("%i\n", myvar.clashy());
}

[[gnu::optimize("O0")]]
int main()
{
  other_func();
}

  parent reply	other threads:[~2022-10-30 23:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 22:10 [Bug translation/107467] New: " volker.weissmann at gmx dot de
2022-10-30 23:22 ` [Bug tree-optimization/107467] " pinskia at gcc dot gnu.org
2022-10-30 23:36 ` pinskia at gcc dot gnu.org [this message]
2022-10-30 23:38 ` [Bug tree-optimization/107467] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-10-30 23:39 ` pinskia at gcc dot gnu.org
2022-10-30 23:39 ` pinskia at gcc dot gnu.org
2022-11-05 10:29 ` rguenth at gcc dot gnu.org
2022-11-21 13:23 ` marxin at gcc dot gnu.org
2022-12-28 10:07 ` marxin at gcc dot gnu.org
2023-01-04 17:29 ` [Bug tree-optimization/107467] [12/13 Regression] Miscompilation involing -Os , -flto and -fno-strict-aliasing since r12-656-ga564da506f52be66 hubicka at gcc dot gnu.org
2023-01-13 11:47 ` rguenth at gcc dot gnu.org
2023-01-13 22:08 ` hubicka at ucw dot cz
2023-05-08 12:25 ` [Bug tree-optimization/107467] [12/13/14 " 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-107467-4-xyB97jjQHd@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).