https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116200
Sergei Trofimovich <slyfox at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |slyfox at gcc dot gnu.org --- Comment #6 from Sergei Trofimovich <slyfox at gcc dot gnu.org> --- I think I'm seeing a similar crash on libgcrypt-1.10.3. Here is the minimal example I extracted from it in case it's easier to explore, fix and add a regression test: // $ cat a.c __attribute__((noipa //, optimize(0) )) static unsigned int KECCAK_F1600_ABSORB_FUNC_NAME(int pos, unsigned long nlanes, int blocklanes) { unsigned int burn = 0; while (nlanes) { switch (blocklanes) { case 21: /* SHAKE128 */ while (nlanes >= 21) { nlanes -= 21; } break; case 18: /* SHA3-224 */ while (nlanes >= 18) { nlanes -= 18; } break; case 17: /* SHA3-256 & SHAKE256 */ while (nlanes >= 17) { nlanes -= 17; } break; case 13: /* SHA3-384 */ while (nlanes >= 13) { nlanes -= 13; } break; case 9: /* SHA3-512 */ while (nlanes >= 9) { nlanes -= 9; } break; } while (nlanes) { nlanes--; if (++pos == blocklanes) { //sink1(hd); pos = 0; break; } } } return burn; } int main() { KECCAK_F1600_ABSORB_FUNC_NAME(0, 1, -1); } $ gcc a.c -o a -O0 && ./a $ gcc a.c -o a -O1 && ./a Segmentation fault (core dumped) I think the sample is still valid: it tries to do nlanes iterations (with some form of unrolling).