summaryrefslogtreecommitdiffstats
path: root/gcc/doc/extend.texi
diff options
context:
space:
mode:
authorthorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-23 15:48:05 +0000
committerthorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4>2002-05-23 15:48:05 +0000
commitdbf6c367801e1bf1d0cec09a2fe8fef7f7957c3f (patch)
treeec1ff9d3e5c1ac88998d2453691cca3c42bc0416 /gcc/doc/extend.texi
parent43a852ea4edb3bace60c8f0880cdc1768ace6151 (diff)
downloadppe42-gcc-dbf6c367801e1bf1d0cec09a2fe8fef7f7957c3f.tar.gz
ppe42-gcc-dbf6c367801e1bf1d0cec09a2fe8fef7f7957c3f.zip
* c-common.c (warn_nonnull): Declare.
(c_common_attribute_table): Add "nonnull" attribute. (handle_nonnull_attribute, check_function_nonnull, nonnull_check_p, check_nonnull_arg, get_nonnull_operand, check_function_arguments, check_function_arguments_recurse): New functions. * c-common.h (warn_nonnull): Declare extern. (check_function_arguments, check_function_arguments_recurse): New prototypes. * c-decl.c (c_decode_option): Add -Wnonnull option. * c-format.c (set_Wformat): Set warn_nonnull if enabling format checking. (format_check_context): New structure. (check_format_info_recurse): Remove recursion and rename to... (check_format_arg): ...this. Update comment. (check_format_info): Use check_function_arguments_recurse. * c-typeck.c (build_function_call): Call check_function_arguments instead of check_function_format. * doc/extend.texi: Document "nonnull" attribute. * doc/invoke.texi: Docuemnt -Wnonnull option. * testsuite/gcc.dg/nonnull-1.c: New test. * testsuite/gcc.dg/nonnull-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53790 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/doc/extend.texi')
-rw-r--r--gcc/doc/extend.texi40
1 files changed, 35 insertions, 5 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 4209f2a5dbc..301db237124 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -1869,6 +1869,7 @@ the enclosing block.
@cindex @code{volatile} applied to function
@cindex @code{const} applied to function
@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
+@cindex functions with non-null pointer arguments
@cindex functions that are passed arguments in registers on the 386
@cindex functions that pop the argument stack on the 386
@cindex functions that do not pop the argument stack on the 386
@@ -1885,11 +1886,11 @@ attributes are currently defined for functions on all targets:
@code{pure}, @code{const},
@code{format}, @code{format_arg}, @code{no_instrument_function},
@code{section}, @code{constructor}, @code{destructor}, @code{used},
-@code{unused}, @code{deprecated}, @code{weak}, @code{malloc}, and
-@code{alias}. Several other attributes are defined for functions on
-particular target systems. Other attributes, including @code{section}
-are supported for variables declarations (@pxref{Variable Attributes})
-and for types (@pxref{Type Attributes}).
+@code{unused}, @code{deprecated}, @code{weak}, @code{malloc},
+@code{alias}, and @code{nonnull}. Several other attributes are defined
+for functions on particular target systems. Other attributes, including
+@code{section} are supported for variables declarations
+(@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}).
You may also specify attributes with @samp{__} preceding and following
each keyword. This allows you to use them in header files without
@@ -2101,6 +2102,35 @@ requested by @option{-ansi} or an appropriate @option{-std} option, or
@option{-ffreestanding} is used. @xref{C Dialect Options,,Options
Controlling C Dialect}.
+@item nonnull (@var{arg-index,...})
+@cindex @code{nonnull} function attribute
+The @code{nonnull} attribute specifies that some function parameters should
+be non-null pointers. For instance, the declaration:
+
+@smallexample
+extern void *
+my_memcpy (void *dest, const void *src, size_t len)
+ __attribute__((nonnull (1, 2)));
+@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. The compiler may also choose to make optimizations based
+on the knowledge that certain function arguments will not be null.
+
+If no argument index list is given to the @code{nonnull} attribute,
+all pointer arguments are marked as non-null. To illustrate, the
+following declaration is equivalent to the previous example:
+
+@smallexample
+extern void *
+my_memcpy (void *dest, const void *src, size_t len)
+ __attribute__((nonnull));
+@end smallexample
+
@item no_instrument_function
@cindex @code{no_instrument_function} function attribute
@opindex finstrument-functions
OpenPOWER on IntegriCloud