https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120903
Bug ID: 120903 Summary: Alias information not used to optimize out hand-written buffer aliasing checks Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: alias, missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: sjames at gcc dot gnu.org Target Milestone: --- Created attachment 61771 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61771&action=edit test.c Mirror version of https://github.com/llvm/llvm-project/issues/146401 """ Clang (and GCC) don't seem to recognize the __fh_overlap macro in godbolt.org/z/EqjKe716r as a buffer aliasing check. The sample was adapted from jvoisin/fortify-headers@master/include/string.h, which is reportedly used in Musl-based Linux distributions like Alpine. In this case, since r was just allocated, the compiler should be able to reason that r cannot overlap with a and delete the __fh_overlap check. It's also important to be able to optimize this because memcpy is the usual pattern to load memory without tripping strict aliasing issues. """