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

            Bug ID: 97641
           Summary: Wrong codegen if optimizer is enabled
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmitriy.ovdienko at gmail dot com
  Target Milestone: ---

g++ optimizer produces wrong code in case if -O3 is used. In case if -O2 and
-O1 are used, app works as expected.

Expected output: matches
In fact output: does not match

```
//
// g++ -O3 test.cpp 
//

#include <cstdio>

int Parse1(char const* ptr) noexcept
{
    bool const negative = '-' == *ptr;
    if (negative)
    {
        ++ptr;
    }

    int result = 0;
    while ('\x01' != *ptr)
    {
        result = result * 10 + *ptr++ - '0';
    }
    return negative ? -result : result;
}

int main()
{
    if(-2147483648 != Parse1("-2147483648\x01")) 
        printf("does not match\n");
    else
        printf("matches\n");
}

```

Reply via email to