https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125116
--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> --- Thanks for filing this bug report, and sorry for the noise. For reference, here's the example on Compiler Explorer: https://godbolt.org/z/xqszz5K6P We added -Wanalyzer-allocation-size in GCC 13: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e6c3bb379f515b27268d08e62b4b3e5d7200b437 and I notice that earlier releases of GCC do also warn for your small example. I wonder if this warning wasn't showing up on Emacs with earlier releases of GCC, and that maybe the changes I've made to path exploration in GCC 16 are now triggering it? (we don't exhaustively check every path through the code). Your example is correct in that nothing accesses the allocated buffer outside the range, but the intent of the warning is to help in cases where the user messes up the calculation of a dynamic buffer. For example, if I add an access to f[10], we correctly warn about the out-of-bounds access: https://godbolt.org/z/9zvacT74h and having a non-multiple of sizeof(int) seems problematic to me. The warning is meant to back off in the case of structs for the common case of implementing inheritance in C by casting to a pointer of the type of the first member, but this is an "int *", rather than a "struct foo *". Can you give an example of where this is firing in Emacs? Is there a valid/idiomatic case I'm missing? Thanks!
