stds.h: introduce AFS_NONNULL
authorGarrett Wollman <wollman@csail.mit.edu>
Wed, 10 Aug 2011 03:50:09 +0000 (23:50 -0400)
committerDerrick Brashear <shadow@dementia.org>
Wed, 10 Aug 2011 17:48:17 +0000 (10:48 -0700)
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>

src/config/stds.h

index 1142050..53badff 100644 (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 */