https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98069
Bug ID: 98069 Summary: Miscompilation with -O3 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: //func.cpp extern long long var_3; extern short var_8; extern int var_17; extern short arr_165[]; long c(long e, long f) { return f ? e : f; } void test() { for (int b = 0; b < 19; b = var_17) for (int d = int(~c(-2147483647 - 1, var_3)) - 2147483647; d < 22; d++) arr_165[d] = var_8; } //driver.cpp #include <stdio.h> long long int var_3 = -166416893043554447LL; short var_8 = (short)27092; unsigned int var_17 = 75036300U; short arr_165[23]; void test(); int main() { for (size_t i_3 = 0; i_3 < 23; ++i_3) arr_165[i_3] = (short)-8885; test(); printf("%d\n", arr_165[0]); } >$ g++ -O3 func.cpp driver.cpp && ./a.out Segmentation fault (core dumped) >$ g++ -O2 func.cpp driver.cpp && ./a.out 27092 gcc version 11.0.0 20201126 (beb9afcaf1466996a301c778596c5df209e7913c)