From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 4FB9D388940E; Mon, 2 Aug 2021 14:51:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FB9D388940E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tom de Vries To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2660] [gcc/doc] Improve nonnull attribute documentation X-Act-Checkin: gcc X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 99b520f031c0e491d7e170916df11dd645d60617 X-Git-Newrev: 7d8577dd46688a3c721fb1e1f271b59f1672e99a Message-Id: <20210802145105.4FB9D388940E@sourceware.org> Date: Mon, 2 Aug 2021 14:51:05 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2021 14:51:05 -0000 https://gcc.gnu.org/g:7d8577dd46688a3c721fb1e1f271b59f1672e99a commit r12-2660-g7d8577dd46688a3c721fb1e1f271b59f1672e99a Author: Tom de Vries Date: Wed Jul 28 15:44:54 2021 +0200 [gcc/doc] Improve nonnull attribute documentation Improve nonnull attribute documentation in a number of ways: Reorganize discussion of effects into: - effects for calls to functions with nonnull-marked parameters, and - effects for function definitions with nonnull-marked parameters. This makes it clear that -fno-delete-null-pointer-checks has no effect for optimizations based on nonnull-marked parameters in function definitions (see PR100404). Mention -Wnonnull-compare. gcc/ChangeLog: 2021-07-28 Tom de Vries PR middle-end/101665 * doc/extend.texi (nonnull attribute): Improve documentation. Diff: --- gcc/doc/extend.texi | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index b83cd4919bb..49df8e6dc38 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3488,17 +3488,37 @@ my_memcpy (void *dest, const void *src, size_t len) @end smallexample @noindent -causes the compiler to check that, in calls to @code{my_memcpy}, -arguments @var{dest} and @var{src} are non-null. If the compiler -determines that a null pointer is passed in an argument slot marked -as non-null, and the @option{-Wnonnull} option is enabled, a warning -is issued. @xref{Warning Options}. Unless disabled by -the @option{-fno-delete-null-pointer-checks} option the compiler may -also perform optimizations based on the knowledge that certain function -arguments cannot be null. In addition, -the @option{-fisolate-erroneous-paths-attribute} option can be specified -to have GCC transform calls with null arguments to non-null functions -into traps. @xref{Optimize Options}. +informs the compiler that, in calls to @code{my_memcpy}, arguments +@var{dest} and @var{src} must be non-null. + +The attribute has an effect both on functions calls and function definitions. + +For function calls: +@itemize @bullet +@item If the compiler determines that a null pointer is +passed in an argument slot marked as non-null, and the +@option{-Wnonnull} option is enabled, a warning is issued. +@xref{Warning Options}. +@item The @option{-fisolate-erroneous-paths-attribute} option can be +specified to have GCC transform calls with null arguments to non-null +functions into traps. @xref{Optimize Options}. +@item The compiler may also perform optimizations based on the +knowledge that certain function arguments cannot be null. These +optimizations can be disabled by the +@option{-fno-delete-null-pointer-checks} option. @xref{Optimize Options}. +@end itemize + +For function definitions: +@itemize @bullet +@item If the compiler determines that a function parameter that is +marked with nonnull is compared with null, and +@option{-Wnonnull-compare} option is enabled, a warning is issued. +@xref{Warning Options}. +@item The compiler may also perform optimizations based on the +knowledge that @code{nonnul} parameters cannot be null. This can +currently not be disabled other than by removing the nonnull +attribute. +@end itemize If no @var{arg-index} is given to the @code{nonnull} attribute, all pointer arguments are marked as non-null. To illustrate, the