stds.h: introduce AFS_NONNULL

AFS_NONNULL wraps the GCC/Clang function attribute __nonnull__, which
tells the compiler and the static analyzer that the pointer arguments
to a function (or specific ones, if provided) cannot be null.  Note
that GCC has only limited support for warning about violations of these
constraints.

Usage examples:
int myfunc(struct foo *a, bar_t, struct baz *c) AFS_NONNULL((1));

tells the compiler that the first argument cannot be null (but the
third one can).

int myfunc2(struct foo *a, bar_t, struct baz *c) AFS_NONNULL();

tells the compiler that both pointer arguments cannot be null.

Change-Id: Id81f0c382a6a3bdd9bf9c716eb4091b433129d69
Suggested-by: Simon Wilkinson, comment on change Ic8751737 (#5180)
Reviewed-on: http://gerrit.openafs.org/5182
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
Garrett Wollman 2011-08-09 23:50:09 -04:00 committed by Derrick Brashear
parent 2cd9d0536b
commit 342be35354

View File

@ -296,14 +296,17 @@ hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return
#define AFS_UNUSED __attribute__((unused))
#define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
#define AFS_NORETURN __attribute__((__noreturn__))
#define AFS_NONNULL(x) __attribute__((__nonnull x))
#elif defined (__clang__)
#define AFS_UNUSED __attribute__((unused))
#define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y)))
#define AFS_NORETURN __attribute__((__noreturn__))
#define AFS_NONNULL(x) __attribute__((__nonnull x))
#else
#define AFS_UNUSED
#define AFS_ATTRIBUTE_FORMAT(style,x,y)
#define AFS_NORETURN
#define AFS_NONNULL(x)
#endif
#endif /* OPENAFS_CONFIG_AFS_STDS_H */