incorrect results for g++ -std=c++11 -O3 -DNDEBUG

Bug #1832132 reported by Bradley Bell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

This bug report is a simplification of the following issue reported against CppAD:
https://github.com/coin-or/CppAD/issues/44

The attached file (to_string.sh) is a bash script that demonstrates the problem.

In summary (of running to_string.sh) the following source code has a different result for ok
depending on if PRINT_BEFOR_CHECK is 0 or 1.

    int max = std::numeric_limits<int>::max();
    os << max;
    std::string s = os.str();
    int check = string2int(s);
# if PRINT_BEFORE_CHECK
    std::cout << "max = " << max << ", check = " << check << "\n";
# endif
    ok &= max == check;

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: g++ 4:7.4.0-1ubuntu2.2
ProcVersionSignature: Ubuntu 4.15.0-51.55-generic 4.15.18
Uname: Linux 4.15.0-51-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.6
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Sun Jun 9 07:58:29 2019
InstallationDate: Installed on 2018-10-24 (227 days ago)
InstallationMedia: Ubuntu 18.04.1 LTS "Bionic Beaver" - Release amd64 (20180725)
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Bradley Bell (bradbell) wrote :
Revision history for this message
Bradley Bell (bradbell) wrote :

I think this is a gcc problem because it reproduces on Fedora 33 with
g++ (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)

In addition, the only compiler flag that is necessary to demonstrate the bug is '-O3' (on my Fedora 33 system). Any other level of optimization passes the test.

Revision history for this message
Bradley Bell (bradbell) wrote :

It turns out it was an error in my test; see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98151

Bradley Bell (bradbell)
Changed in gcc-defaults (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.