Page MenuHomeFreeBSD

Disable errors for -Wnonnull for the kernel for GCC 12.
ClosedPublic

Authored by jhb on Dec 7 2022, 8:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 23, 4:45 AM
Unknown Object (File)
Thu, Nov 21, 6:50 PM
Unknown Object (File)
Wed, Nov 20, 9:19 PM
Unknown Object (File)
Mon, Nov 18, 9:07 AM
Unknown Object (File)
Sun, Nov 17, 10:45 PM
Unknown Object (File)
Sat, Nov 16, 1:02 AM
Unknown Object (File)
Thu, Nov 7, 3:43 PM
Unknown Object (File)
Sun, Nov 3, 11:54 PM
Subscribers

Details

Summary

The USB code and some other places raise false positives when a NULL
pointer is passed to an inlined function along with a separate length
and the compiler can't determine that the separate length of 0
prevents the use of the NULL pointer.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Dec 7 2022, 8:36 PM
jhb created this revision.
This revision was not accepted when it landed; it landed in state Needs Review.Dec 21 2022, 6:51 PM
This revision was automatically updated to reflect the committed changes.

What are the functions? Generally, passing a null pointer to a standard string function invokes UB regardless of the passed size, and some compilers do make optimizations based on this assumption.

I built with gcc12 in Cirrus-CI and get a few Wnonnull warnings. D39947 is a fix for one of them, PR271227 is a bug report for one of them, and the last one is:

In file included from /tmp/cirrus-ci-build/sys/sys/bus.h:169,
                 from /tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:37:
In function 'ccp_do_xts',
    inlined from 'ccp_do_blkcipher' at /tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1614:11,
    inlined from 'ccp_authenc' at /tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1707:11:
/tmp/cirrus-ci-build/sys/sys/systm.h:266:33: warning: argument 2 null where non-null expected [-Wnonnull]
  266 | #define memcpy(to, from, len)   __builtin_memcpy((to), (from), (len))
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1433:25: note: in expansion of macro 'memcpy'
 1433 |                         memcpy(&qp->completions_ring[qp->cq_tail], cctx,
      |                         ^~~~~~
/tmp/cirrus-ci-build/sys/sys/systm.h:266:33: note: in a call to built-in function '__builtin_memcpy'
  266 | #define memcpy(to, from, len)   __builtin_memcpy((to), (from), (len))
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1433:25: note: in expansion of macro 'memcpy'
 1433 |                         memcpy(&qp->completions_ring[qp->cq_tail], cctx,
      |                         ^~~~~~
In function 'ccp_do_blkcipher',
    inlined from 'ccp_authenc' at /tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1707:11:
/tmp/cirrus-ci-build/sys/sys/systm.h:266:33: warning: argument 2 null where non-null expected [-Wnonnull]
  266 | #define memcpy(to, from, len)   __builtin_memcpy((to), (from), (len))
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1631:25: note: in expansion of macro 'memcpy'
 1631 |                         memcpy(&qp->completions_ring[qp->cq_tail], cctx,
      |                         ^~~~~~
/tmp/cirrus-ci-build/sys/sys/systm.h:266:33: note: in a call to built-in function '__builtin_memcpy'
  266 | #define memcpy(to, from, len)   __builtin_memcpy((to), (from), (len))
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cirrus-ci-build/sys/crypto/ccp/ccp_hardware.c:1631:25: note: in expansion of macro 'memcpy'
 1631 |                         memcpy(&qp->completions_ring[qp->cq_tail], cctx,
      |                         ^~~~~~