https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114554
Bug ID: 114554 Summary: In O2-3 optimization, this code runs in an infinite loop. Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: nmodnation at gmail dot com Target Milestone: --- #include <stdio.h> #include <stdint.h> static void wymum(uint64_t* p1, uint64_t* p2) { int64_t v1; int64_t v2; int64_t v3; int64_t v4; int64_t v5; int64_t v6; int64_t v7; int64_t v8; int64_t v9; int64_t v10; int64_t v11; int64_t t1; int32_t t2; int64_t t3; int64_t t4; t1 = *p1; t1 = (uint64_t)t1 >> (uint64_t)32; v1 = t1; t1 = *p2; t1 = (uint64_t)t1 >> (uint64_t)32; v2 = t1; t2 = (uint32_t)*p1; v3 = (uint64_t)(uint32_t)t2; t2 = (uint32_t)*p2; v4 = (uint64_t)(uint32_t)t2; t1 = v1; t1 *= v2; v5 = t1; t1 = v1; t1 *= v4; v6 = t1; t1 = v2; t1 *= v3; v7 = t1; t1 = v3; t1 *= v4; v8 = t1; t1 = v6; t1 = (uint64_t)t1 << (uint64_t)32; t3 = v8; t3 += t1; v9 = t3; t2 = (uint64_t)v9 < (uint64_t)v8 ? 1 : 0; v10 = (int64_t)t2; t1 = v7; t1 = (uint64_t)t1 << (uint64_t)32; t3 = v9; t3 += t1; v11 = t3; t2 = (uint64_t)v11 < (uint64_t)v9 ? 1 : 0; t1 = (int64_t)t2; v10 += t1; t1 = v6; t1 = (uint64_t)t1 >> (uint64_t)32; t3 = v7; t3 = (uint64_t)t3 >> (uint64_t)32; t4 = v5; t4 += t1; t4 += t3; t4 += v10; *p1 = v11; *p2 = t4; return; } static uint64_t wymix(uint64_t p1, uint64_t p2) { wymum(&p1, &p2); return p1 ^ p2; } static uint64_t wyrand(int64_t* p1) { *p1 += 3257665815644502181; return wymix(*p1, *p1 ^ -8378864009470890807); } int main(int argc, char **argv) { int64_t seed = 1; int i = 0; for (; i < 10; i++) { printf("%llx\n", wyrand(&seed)); } return 0; } // gcc -O2 -o bug bug.c It is not a solution, but it can be resolved by modifying it as shown below. 1. static uint64_t wyrand(int64_t* p1) => static uint64_t wyrand(uint64_t* p1) 2. int64_t seed = 1; => uint64_t seed = 1;