On 1 September 2016 at 21:28, Martin Sebor <mse...@gmail.com> wrote: >> The attached version passes bootstrap+test on ppc64le-linux-gnu. >> Given that it only looks if parameters are restrict qualified and not >> how they're used inside the callee, >> this can have false positives as in above test-cases. >> Should the warning be put in Wextra rather than Wall (I have left it >> in Wall in the patch) or only enabled with -Wrestrict ? > > > Awesome! I've wished for years for a warning like this! Thanks for experimenting with the patch! > > I'm curious if you've tested other examples from 6.7.3.1 of C11 > besides Example 3. Example 4 seems like something GCC should be > able to detect but I didn't get a warning with the patch. Oops, I wasn't aware about example 4, and only implemented the warning for function call. IIUC, the assignment p = q will result in undefined behavior if q is qualified with restrict and p is at an outer-scope relative to q ? > > I would expect the warning to be especially valuable with string > manipulation functions like memcpy that have undefined behavior > for overlapping regions, such as in: > > char a[4]; > > void g (void) > { > __builtin_memcpy (a, a + 1, 3); > } > > But here, too, I didn't get a warning. I understand that this > case cannot be handled for arbitrary functions whose semantics > aren't known but with standard functions for which GCC provides > intrinsics the effects are known and aliasing violations can in > common cases be detected. Indeed, thanks for the suggestions. I will add support for some standard functions in a follow-up patch.
Thanks, Prathamesh > > Martin