[Bug c++/98151] New: integer output gives different results with -O2 and -O3

bradley_bell at yahoo dot com gcc-bugzilla@gcc.gnu.org
Sat Dec 5 03:11:33 GMT 2020


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

            Bug ID: 98151
           Summary: integer output gives different results with -O2 and
                    -O3
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bradley_bell at yahoo dot com
  Target Milestone: ---

Created attachment 49688
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49688&action=edit
bash shell script that creates the souce code, compiles, and runs the test

The attached bash script creates a c++ file called int_output.cpp, then
compiles and runs the program. If you run the script with no arguments you will
get the following usage message:

    usage: ./int_output.sh print optimize
    print:    is either 0 or 1
    optimize: is -O2 or -O3

    If print is 0 and optimize is -O3, the test will fail.
    Otherwise, the test will pass

The program starts with the maximum integer, uses a stringstream to convert it
to a string, and then converts it back to an integer. It then checks that the
result is the maximum integer; i.e., the integer it started with.

If print is 0 (1) the value of the starting and ending integers are printed.
The optimize argument determines the optimization level during the g++
compliation.

The only case that fails is when print is 0 and optimize is -O3.
In addition, if one uses clang++, instead of g++, all the cases give the
correct result.


More information about the Gcc-bugs mailing list