https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
--- Comment #35 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 52643 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52643&action=edit gcc12-pr99578-wip.patch What we could do is differentiate between the invalid constant addresses from pointer arithmetics on NULL or propagation of NULL into &ptr->field and valid (type *)constant used heavily in real-world code and accepted by all major compilers by representing the former internally as &MEM_REF[(void *)0B + offset] while the user (type *)constant as INTEGER_CSTs. That in full seems like a stage1 task because we'd need to ensure we don't regress much by doing that. Some things would be unavoidable (like avoiding SCCVN of those pointer INTEGER_CSTs vs. the &MEM_REF[(void *)0B + offset] form), e.g. equality comparison of &MEM_REF[(void *)0B + CST] vs. (void *)CST should be optimized etc., and we would need to force that form even on say (int *)0 + 24 etc. in the FEs. But we badly need to fix this for GCC 12 and backport to GCC 11. So this WIP patch treats addresses in the first page (a param defaulting to 4KB) temporarily as emitting the warnings as before in GCC 11/12, and only creates the &MEM_REF[(void *)0B + offset] form for larger offsets which will make them very rare. Some further tweaks will be needed on the gimple-array-bounds* etc. side so that we treat those &MEM_REF[(void *)0B + offset] as equivalent to the GCC 11 up to current trunk handling of (void *)offset, so that say on: struct S { int a, b[4]; }; struct T { int a, b[8192], c[4]; }; void foo (struct S *p) { if (p) return; __builtin_memset (p->b, 0, sizeof p->b); } void bar (struct T *p) { if (p) return; __builtin_memset (p->c, 0, sizeof p->c); } one gets the same warnings rather than different. On IRC Richi suggested just the params.opt and pointer-query.cc (compute_objsize_r) hunks which would only warn above in foo and not in bar.