https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106070
Bug ID: 106070 Summary: Wrong code with -O1 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vsevolod.livinskiy at gmail dot com Target Milestone: --- GCC produces incorrect code with -O1. I was not able to merge the test into a single file. Reproducer: // func.cpp extern unsigned var_2; extern int var_4; extern signed char var_10; extern unsigned long long arr_252; void test() { for (unsigned a = 0; a < (unsigned char)var_10; a += 2) arr_252 = var_2 != var_4 ? var_4 : (long)var_2; } //driver.cpp #include <stdio.h> unsigned int var_2 = 1; int var_4 = -1; signed char var_10 = (signed char)(-127 - 1); unsigned long long int arr_252; void test(); int main() { test(); printf("%llx\n", arr_252); if (arr_252 != 0xffffffffffffffff) __builtin_abort(); } Error: >$ g++ -O0 func.cpp driver.cpp && ./a.out ffffffffffffffff >$ g++ -O1 func.cpp driver.cpp && ./a.out ffffffff Aborted (core dumped) gcc version 13.0.0 20220623 (31ce821a790caec8a2849dd67a9847e78a33d14c)