https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117100
Bug ID: 117100 Summary: [13 regression] ImageMagick miscompiled with -O1 -funswitch-loops Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: sjames at gcc dot gnu.org Target Milestone: --- Hopefully this reduction is right. Originally reported downstream in Gentoo at https://bugs.gentoo.org/941208 where IM would give a black PNG when built with -O3 with GCC 13. ``` #include <stdbool.h> #include <stdlib.h> static int count = 0; double PerceptibleReciprocal(const double x) { double sign; sign = x < 0.0 ? -1.0 : 1.0; return (sign / 1.0e-12); } bool CompositeImage(int compose) { double Sa = count; double pixel = 65535; double gamma = 1.0; for (int i = 0; i < 3; i++) { switch (compose) { case 1: case 61: { pixel = 65535 * gamma * Sa; break; } case 39: { gamma = PerceptibleReciprocal(0); break; } case 17: { /* When things are OK, we reach here. */ exit(0); break; } default: { break; } } /* This must be a switch to break. */ switch (compose) { case 20: case 30: case 50: { gamma = PerceptibleReciprocal(0); break; } default: { break; } } if (pixel < 0 || pixel >= 65535) { __builtin_abort(); } } count++; return true; } int main() { CompositeImage(1); CompositeImage(17); } ```