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)
Thu, Nov 7, 3:43 PM
Unknown Object (File)
Sun, Nov 3, 11:54 PM
Unknown Object (File)
Fri, Nov 1, 2:40 AM
Unknown Object (File)
Thu, Oct 31, 5:27 AM
Unknown Object (File)
Sep 11 2024, 7:57 PM
Unknown Object (File)
Sep 5 2024, 5:29 AM
Unknown Object (File)
Aug 31 2024, 9:52 PM
Unknown Object (File)
Aug 25 2024, 6:50 AM
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 Skipped
Unit
Tests Skipped
Build Status
Buildable 48644
Build 45530: arc lint + arc unit

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,
      |                         ^~~~~~