On 10/21/23 05:09, Martin Uecker wrote:

C programmers increasingly use static to indicate that
pointer parameters are non-null.  Clang can exploit this
for warnings and optimizations.  GCC has some warnings
but not all warnings it has for nonnull.  Below is a
patch to add a nonnull attribute automatically for such
arguments and to remove the special and more limited
nonnull warnings for static. This patch found some
misplaced annotationsĀ in one of my projects via
-Wnonnull-compare which clang does not seem to have,
so IĀ think this could be useful.

     c: Synthesize nonnull attribute for parameters declared with static 
[PR110815]
Parameters declared with `static` are nonnull. We synthesize
     an artifical nonnull attribute for such parameters to get the
     same warnings and optimizations.
Bootstrapped and regression tested on x86. PR c/102558
            PR 102556
             PR c/110815
gcc/c-family:
             * c-attribs.cc (build_attr_access_from_parms): Synthesize
             nonnull attribute for parameters declared with `static`.
gcc:
             * gimple-ssa-warn-access.cc 
(pass_waccess::maybe_check_access_sizes):
             remove warning for parameters declared with `static`.
gcc/testsuite:
             * gcc.dg/Wnonnull-8.c: Adapt test.
             * gcc.dg/Wnonnull-9.c: New test.
This is OK -- assuming you did the usual bootstrap & regression test cycle.

Jeff

Reply via email to