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

            Bug ID: 98640
           Summary: GCC produces incorrect code with -O1 and higher
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Reproducer:
#include <stdio.h>

unsigned long long int var_0 = 18128133247277979402ULL;
long long int var_14 = 6557021550272328915LL;
unsigned long long int var_83 = 10966786425750692026ULL;

void test() {
  var_14 = var_0 + (bool)7;
  var_83 = 1 + (int)var_0; // 1 + 888395530
}

int main() {
    test();
    printf("%llu\n", var_83);
}

https://godbolt.org/z/axYx1f

>$ g++ -O0 driver.cpp && ./a.out 
888395531
>$ g++ -O1 driver.cpp && ./a.out 
18128133247277979403

gcc version 11.0.0 20210112 (cf2ac1c30af0fa783c8d72e527904dda5d8cc330)

Reply via email to