public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Hongbo Liu <lhbf@qq.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++ bugfix: inconsistent runtime beahavior when have -O2
Date: Mon, 6 Jun 2022 02:51:17 -0700	[thread overview]
Message-ID: <CA+=Sn1mHU04PL7z7th1gtSdOEohbbnhX95Fnngq6nC-S3Nbnsg@mail.gmail.com> (raw)
In-Reply-To: <tencent_18F6B45554A14F3A8BF722D8C04B1FD70407@qq.com>

On Mon, Jun 6, 2022 at 2:12 AM Hongbo Liu via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> This is my first time using email patch, please correct me if there is any error. Thanks!
>
>
> I found a c++ optimization bug first introduced via commit&nbsp;520d5ad337eaa15860a5a964daf7ca46cf31c029, which will make program compiled with -O2 have unexpected behavior.

Except your testcase violates C/C++ aliasing rules.
You store to offset_delta via int64_t (which is long on x86_64) but
then do a load via long long.
If you fix the testcase, it works correctly at -O2 and above. If you
don't want strict aliasing to be turned on you can use
-fno-strict-aliasing.

Your patch is wrong as now none of the modref data will be used which
is exposing the bug in the testcase and it is a bug in the source code
you are compiling.

As for how to add the testcase,
https://gcc.gnu.org/wiki/HowToPrepareATestcase does have some
information.
So does https://gcc.gnu.org/onlinedocs/gccint/Testsuites.html#Testsuites .


Thanks,
Andrew Pinski

>
>
> How to produce
>
>
> 1. Checkout to latest master commit:&nbsp;c4d702fb3c1e2f6e1bc8711da81bff59543b1b19
> 2. Build and install the gcc;
> 3. Compile the attached file `test.cc` with command: `latest-g++ -std=c++20 -g0 -O1 test.cc -o test_o1`;
> 4. The output of `./test_o1` will be `offset delta: 5`;
> 5.&nbsp; Compile the attached file `test.cc` with command: `latest-g++ -std=c++20 -g0 -O2 test.cc -o test_o2`;
> 6. The output of `./test_o2` will be `offset delta: 0`;
>
>
> The program behavior with `-O2` is inconsistent with `-O1` and unexpected.
>
>
> How to fix
>
>
> The bug was introduced via commit 520d5ad337eaa15860a5a964daf7ca46cf31c029. The attached patch file could fix the problem and make `-O2` and `-O1` have same behavior.
>
>
> Request for suggestion
>
>
> I could not find and document about how to add this kind of test, could anyone give me some suggestions?

      reply	other threads:[~2022-06-06  9:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06  9:11 Hongbo Liu
2022-06-06  9:51 ` Andrew Pinski [this message]

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='CA+=Sn1mHU04PL7z7th1gtSdOEohbbnhX95Fnngq6nC-S3Nbnsg@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=lhbf@qq.com \
    /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).