https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98357
Bug ID: 98357 Summary: Bounds check not eliminated Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: jmuizelaar at mozilla dot com Target Milestone: --- #include <stdlib.h> char foo(char* data, size_t len, size_t i, size_t j) { if (i < len && j <= i) { if (j < len) { return data[j]; } else { exit(1); } } else { return 0; } } compiles to: foo(char*, unsigned long, unsigned long, unsigned long): cmp rdx, rsi jnb .L4 cmp rdx, rcx jb .L4 cmp rsi, rcx jbe .L3 movzx eax, BYTE PTR [rdi+rcx] ret .L4: xor eax, eax ret .L3: push rax mov edi, 1 call exit The call to exit should be eliminated.