https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109578
Bug ID: 109578 Summary: fail to remove dead code due to division by zero Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- This is about the opposite of the invalid bug 29968: #include <stdio.h> int f (int i, int k) { if (k == 0) printf ("k = 0\n"); return i/k; } int main (void) { return f (1, 0); } With gcc-12 (Debian 12.2.0-14) 12.2.0 and -O3 optimization, I get: k = 0 zsh: illegal hardware instruction (core dumped) ./tst But since the case k == 0 corresponds to an undefined behavior (which is the justification behind that GCC is correct in bug 29968), the code if (k == 0) printf ("k = 0\n"); should have been removed as an optimization.