With more testing (building GDB, Glibc, Busybox, and the Linux kernel) I found a few bugs and weaknesses in the initial patch. Attached is version 2 that fixes the uncovered problems and makes further enhancements to handle more cases. Martin On 07/16/2017 05:47 PM, Martin Sebor wrote: > Being implemented in the front end, the -Wrestrict warning > detects only trivial instances of violations. The attached > patch extends the implementation to the middle-end where > data flow and alias analysis can be combined to detect even > complex cases of overlap. This work is independent of but > follows on the patch below (waiting for review): > > https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00036.html > > The changes rely on extending the tree-ssa-{alias,structalias} > machinery in a simple way to answer the "must-alias" kind of > question in addition to the current "may-alias." > > The rest of the changes are in gimple-fold.c, tree-ssa-strlen.c, > and builtins.c. > > Even though this change makes -Wrestrict a lot more useful, it's > not a complete implementation. Not all built-ins are handled yet > (e.g., strncat), and support for user-defined functions is still > subject to the limitations of the front end implementation. To > complete the support, handlers for the missing string built-ins > will need to be added to tree-ssa-strlen.c, and the remaining > bits should be moved from the front end to somewhere in > the middle-end (e.g., calls.c). > > Martin