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 via email to