https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120948
Bug ID: 120948 Summary: Cannot detect potential division-by-zero when numerator is 1 and denominator is variable Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: h13958451065 at 163 dot com Target Milestone: --- The bug was introduced by:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95424 When encountering an expression like 1/X where X is a variable (potentially zero), GCC cannot statically determine whether X equals zero. Currently, aside from using -fnon-call-exceptions to disable optimizations: Are there other ways to make GCC recognize and handle the zero-check for X? Could GCC provide better user diagnostics to highlight this risky pattern?