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 520d5ad337eaa15860a5a964daf7ca46cf31c029, which will make program 
compiled with -O2 have unexpected behavior.


How to produce


1. Checkout to latest master 
commit: 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.  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?

Attachment: test.cc
Description: Binary data

Attachment: 0001-PATCH-c-bugfix-inconsistent-logic-when-have-O2.patch
Description: Binary data

Reply via email to