https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119946
Bug ID: 119946 Summary: memset/memcpy with a null argument should be folded into `if (size_arg) __builtin_unreachable();` Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` unsigned char my_func(int n) { __builtin_memset((void*)0, 0, n); return n+1; } ``` Since C23, the memset here is only undefined if `n!=0`, I think we should be able to fold the memset into: ``` if (n != 0) __builtin_unreachable(); ``` which is exactly what LLVM does starting in LLVM 20. Thought maybe a trap instead would be better. If anything this could be part of path isolation. Note I noticed this while working through the review of the patches of PR 67797.