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

            Bug ID: 94727
           Summary: GCC produces incorrect code with -O3
           Product: gcc
           Version: 10.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: ---

GCC produces incorrect code with -O3.

Reproducer:
>$ cat func.cpp 
extern bool var_3;
extern unsigned long long int var_11;
extern unsigned char arr_41 [14] [14] [19] [16] [18] ;
extern long long int arr_42 [14] [14] [19] [16] [18] ;

void test() {
  for (int a = 0; a < 3; a++)
    for (char b = 0; b < 3; b = 4)
      for (int c = 0; c < 8; c++)
        for (short d = 0; d < 5; d += 4)
          for (char e = 0; e < 17; e++)
            arr_42[a][b][c][d][e] = (arr_41[a][b][c][d][e] < var_11) > var_3;
}

>$ cat driver.cpp 
#include <stdio.h>

bool var_3 = (bool)0;
unsigned long long int var_11 = 14035841137156193017ULL;
unsigned char arr_41 [14] [14] [19] [16] [18] ;
long long int arr_42 [14] [14] [19] [16] [18] ;
void test();

int main() {
    for (size_t i_0 = 0; i_0 < 14; ++i_0)
        for (size_t i_1 = 0; i_1 < 14; ++i_1)
            for (size_t i_2 = 0; i_2 < 19; ++i_2)
                for (size_t i_3 = 0; i_3 < 16; ++i_3)
                    for (size_t i_4 = 0; i_4 < 18; ++i_4)
                        arr_41 [i_0] [i_1] [i_2] [i_3] [i_4] = (unsigned
char)226;
    for (size_t i_0 = 0; i_0 < 14; ++i_0)  
        for (size_t i_1 = 0; i_1 < 14; ++i_1)
            for (size_t i_2 = 0; i_2 < 19; ++i_2)
                for (size_t i_3 = 0; i_3 < 16; ++i_3)
                    for (size_t i_4 = 0; i_4 < 18; ++i_4)
                        arr_42 [i_0] [i_1] [i_2] [i_3] [i_4] =
-5577957210778461327LL;
    test();
    printf("%lld\n", arr_42[0][0][0][0][0]);
}

Error:
>$ g++ func.cpp driver.cpp -O0 && ./a.out 
1
>$ g++ func.cpp driver.cpp -O3 && ./a.out 
0

GCC version:
10.0.1 (87841658d4fa5174d1797ee0abc73b3b3f11cad4)

Reply via email to